mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 03:41:01 +00:00
Add log-level option to cli (#584)
* add log-level option to cli * use app.Before * rm not needed
This commit is contained in:
parent
e49f2e6061
commit
f1e2f3dcad
3 changed files with 29 additions and 0 deletions
|
@ -47,6 +47,11 @@ var GlobalFlags = []cli.Flag{
|
|||
Usage: "socks proxy ignored",
|
||||
Hidden: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
EnvVars: []string{"WOODPECKER_LOG_LEVEL"},
|
||||
Name: "log-level",
|
||||
Usage: "set logging level",
|
||||
},
|
||||
}
|
||||
|
||||
// FormatFlag return format flag with value set based on template
|
||||
|
|
23
cli/common/zerologger.go
Normal file
23
cli/common/zerologger.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func SetupConsoleLogger(c *cli.Context) error {
|
||||
if c.IsSet("log-level") {
|
||||
level := c.String("log-level")
|
||||
lvl, err := zerolog.ParseLevel(level)
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("unknown logging level: %s", level)
|
||||
}
|
||||
zerolog.SetGlobalLevel(lvl)
|
||||
}
|
||||
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
|
||||
log.Logger = log.With().Caller().Logger()
|
||||
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -63,6 +63,7 @@ func main() {
|
|||
Out: os.Stderr,
|
||||
},
|
||||
)
|
||||
app.Before = common.SetupConsoleLogger
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
zlog.Fatal().Err(err).Msg("error running cli")
|
||||
|
|
Loading…
Reference in a new issue