woodpecker/cli/common/zerologger.go
6543 f1e2f3dcad
Add log-level option to cli (#584)
* add log-level option to cli

* use app.Before

* rm not needed
2021-12-10 21:49:22 +01:00

23 lines
546 B
Go

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
}