Skip to content

Commit

Permalink
feat: output json logs by default (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarabas committed Jul 12, 2022
1 parent 328aaa8 commit 0c8c31e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/server.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ search:

log:
level: trace
format: console

foundationdb:
cluster_file: "./test/config/fdb.cluster"
13 changes: 9 additions & 4 deletions util/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
)

type LogConfig struct {
Level string
Level string
Format string
}

// trim full path. output in the form directory/file.go
Expand All @@ -49,14 +50,18 @@ func consoleFormatCaller(i interface{}) string {
func Configure(config LogConfig) {
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
output.FormatCaller = consoleFormatCaller
lvl, err := zerolog.ParseLevel(config.Level)
if err != nil {
log.Error().Err(err).Msg("error parsing log level. defaulting to info level")
lvl = zerolog.InfoLevel
}
log.Logger = zerolog.New(output).Level(lvl).With().Timestamp().CallerWithSkipFrameCount(3).Stack().Logger()
if config.Format == "console" {
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
output.FormatCaller = consoleFormatCaller
log.Logger = zerolog.New(output).Level(lvl).With().Timestamp().CallerWithSkipFrameCount(3).Stack().Logger()
} else {
log.Logger = zerolog.New(os.Stdout).Level(lvl).With().Timestamp().CallerWithSkipFrameCount(3).Stack().Logger()
}
}

func E(err error) bool {
Expand Down

0 comments on commit 0c8c31e

Please sign in to comment.