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:
John Olheiser 2021-10-16 17:41:36 -05:00 committed by GitHub
parent ed03a318c5
commit 03bb0e69d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 14 deletions

View file

@ -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

View file

@ -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",

View file

@ -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",

View file

@ -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")
}