mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 10:07:21 +02:00
Replace debug with log-level flag (#440)
* Add logging level to CLI and API Signed-off-by: jolheiser <john.olheiser@gmail.com> # Conflicts: # server/router/router.go * Apply suggestions from code review Co-authored-by: Anbraten <anton@ju60.de> * Refactor log level Signed-off-by: jolheiser <john.olheiser@gmail.com> * Remove API Signed-off-by: jolheiser <john.olheiser@gmail.com> * Fix API imports Signed-off-by: jolheiser <john.olheiser@gmail.com> * do not relay on external default Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
parent
ed03a318c5
commit
03bb0e69d8
@ -49,12 +49,6 @@ func loop(c *cli.Context) error {
|
||||
hostname, _ = os.Hostname()
|
||||
}
|
||||
|
||||
if c.BoolT("debug") {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
} else {
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
}
|
||||
|
||||
if c.Bool("pretty") {
|
||||
log.Logger = log.Output(
|
||||
zerolog.ConsoleWriter{
|
||||
@ -64,6 +58,23 @@ func loop(c *cli.Context) error {
|
||||
)
|
||||
}
|
||||
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
if c.BoolT("debug") {
|
||||
if c.IsSet("debug") {
|
||||
log.Warn().Msg("--debug is deprecated, use --log-level instead")
|
||||
}
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
if c.IsSet("log-level") {
|
||||
logLevelFlag := c.String("log-level")
|
||||
lvl, err := zerolog.ParseLevel(logLevelFlag)
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("unknown logging level: %s", logLevelFlag)
|
||||
}
|
||||
zerolog.SetGlobalLevel(lvl)
|
||||
}
|
||||
|
||||
counter.Polling = c.Int("max-procs")
|
||||
counter.Running = 0
|
||||
|
||||
|
@ -43,6 +43,11 @@ var flags = []cli.Flag{
|
||||
Name: "debug",
|
||||
Usage: "enable agent debug mode",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "WOODPECKER_LOG_LEVEL",
|
||||
Name: "log-level",
|
||||
Usage: "set logging level",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
EnvVar: "WOODPECKER_DEBUG_PRETTY",
|
||||
Name: "pretty",
|
||||
|
@ -26,6 +26,11 @@ var flags = []cli.Flag{
|
||||
Name: "debug",
|
||||
Usage: "enable server debug mode",
|
||||
},
|
||||
cli.StringFlag{
|
||||
EnvVar: "WOODPECKER_LOG_LEVEL",
|
||||
Name: "log-level",
|
||||
Usage: "set logging level",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
EnvVar: "WOODPECKER_DEBUG_PRETTY",
|
||||
Name: "pretty",
|
||||
|
@ -52,14 +52,6 @@ import (
|
||||
|
||||
func loop(c *cli.Context) error {
|
||||
|
||||
// debug level if requested by user
|
||||
// TODO: format output & options to switch to json aka. option to add channels to send logs to
|
||||
if c.Bool("debug") {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
} else {
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
}
|
||||
|
||||
if c.Bool("pretty") {
|
||||
log.Logger = log.Output(
|
||||
zerolog.ConsoleWriter{
|
||||
@ -69,6 +61,23 @@ func loop(c *cli.Context) error {
|
||||
)
|
||||
}
|
||||
|
||||
// debug level if requested by user
|
||||
// TODO: format output & options to switch to json aka. option to add channels to send logs to
|
||||
zerolog.SetGlobalLevel(zerolog.WarnLevel)
|
||||
if c.Bool("debug") {
|
||||
log.Warn().Msg("--debug is deprecated, use --log-level instead")
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
if c.IsSet("log-level") {
|
||||
logLevelFlag := c.String("log-level")
|
||||
lvl, err := zerolog.ParseLevel(logLevelFlag)
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("unknown logging level: %s", logLevelFlag)
|
||||
}
|
||||
zerolog.SetGlobalLevel(lvl)
|
||||
}
|
||||
|
||||
if c.String("server-host") == "" {
|
||||
log.Fatal().Msg("WOODPECKER_HOST is not properly configured")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user