Skip to content

Commit

Permalink
Merge pull request #586 from cgalibern/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cgalibern authored Aug 26, 2024
2 parents f5d77e6 + 6ae6e0a commit 3275386
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
4 changes: 2 additions & 2 deletions core/om/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package om
import (
// Necessary to use go:embed
_ "embed"

"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -189,7 +188,8 @@ func init() {
root.PersistentFlags().StringVar(&configFlag, "config", "", "Config file (default \"$HOME/.opensvc.yaml\").")
root.PersistentFlags().StringVar(&colorFlag, "color", "auto", "Output colorization yes|no|auto.")
root.PersistentFlags().StringVar(&serverFlag, "server", "", "URI of the opensvc api server.")
root.PersistentFlags().StringVar(&logFlag, "log", "", "Display logs on the console at the specified level.")
root.PersistentFlags().StringVar(&logFlag, "log", "info", "Display logs on the console with one of the specified level: "+
"trace, debug, info, warn, error, fatal, panic, none")
root.PersistentFlags().BoolVar(&callerFlag, "caller", false, "Show caller <file>:<line> in logs.")
}

Expand Down
31 changes: 10 additions & 21 deletions util/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,20 @@ func SetDefaultConsoleWriter(w zerolog.ConsoleWriter) {
consoleWriter = w
}

func Logger() zerolog.Logger {
return log.Logger
}

// Configure sets up the logging framework
func Configure(config Config) error {
var writers []io.Writer

if config.Level == "none" {
zerolog.SetGlobalLevel(zerolog.NoLevel)
} else if config.Level == "" {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
} else if configLevel, err := zerolog.ParseLevel(config.Level); err != nil {
return fmt.Errorf("invalid log level %s", config.Level)
} else {
zerolog.SetGlobalLevel(configLevel)
}

zerolog.TimeFieldFormat = time.RFC3339Nano

if writer := journald.NewJournalDWriter(); writer != nil {
Expand All @@ -122,23 +128,6 @@ func Configure(config Config) error {

logger := log.Output(mw)

switch config.Level {
case "debug":
logger = logger.Level(zerolog.DebugLevel)
case "info":
logger = logger.Level(zerolog.InfoLevel)
case "warn", "warning":
logger = logger.Level(zerolog.WarnLevel)
case "error":
logger = logger.Level(zerolog.ErrorLevel)
case "fatal":
logger = logger.Level(zerolog.FatalLevel)
case "panic":
logger = logger.Level(zerolog.PanicLevel)
default:
logger = logger.Level(zerolog.InfoLevel)
}

if config.WithCaller {
// skip one more for plog wrappers
logger = logger.With().CallerWithSkipFrameCount(zerolog.CallerSkipFrameCount + 1).Logger()
Expand Down

0 comments on commit 3275386

Please sign in to comment.