2021-12-10 20:49:22 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetupConsoleLogger(c *cli.Context) error {
|
2022-04-05 12:10:10 +00:00
|
|
|
level := c.String("log-level")
|
|
|
|
lvl, err := zerolog.ParseLevel(level)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Msgf("unknown logging level: %s", level)
|
2021-12-10 20:49:22 +00:00
|
|
|
}
|
2022-04-05 12:10:10 +00:00
|
|
|
zerolog.SetGlobalLevel(lvl)
|
2021-12-10 20:49:22 +00:00
|
|
|
if zerolog.GlobalLevel() <= zerolog.DebugLevel {
|
|
|
|
log.Logger = log.With().Caller().Logger()
|
|
|
|
log.Log().Msgf("LogLevel = %s", zerolog.GlobalLevel().String())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|