diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go index 507077953..faa1a1d7a 100644 --- a/cmd/agent/agent.go +++ b/cmd/agent/agent.go @@ -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 diff --git a/cmd/agent/flags.go b/cmd/agent/flags.go index 254b8d17d..d87d27952 100644 --- a/cmd/agent/flags.go +++ b/cmd/agent/flags.go @@ -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", diff --git a/cmd/server/flags.go b/cmd/server/flags.go index a0087f7c7..f9bb83b1b 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -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", diff --git a/cmd/server/server.go b/cmd/server/server.go index 74ea3240d..3ae8abac5 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -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") }