Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Honor the log-format parameter for debug logs #988

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logger

import (
"fmt"
"io"
golog "log"
"os"
"path"
Expand Down Expand Up @@ -32,7 +33,7 @@ func New(v *viper.Viper, fs afero.Afero) log.Logger {

fullPathCaller := pathCaller(6)
var stdoutLogger log.Logger
stdoutLogger = withFormat(viper.GetString("log-format"))
stdoutLogger = withFormat(viper.GetString("log-format"), os.Stdout)
stdoutLogger = log.With(stdoutLogger, "ts", log.DefaultTimestampUTC)
stdoutLogger = log.With(stdoutLogger, "caller", fullPathCaller)
stdoutLogger = withLevel(stdoutLogger, v.GetString("log-level"))
Expand All @@ -52,7 +53,7 @@ func New(v *viper.Viper, fs afero.Afero) log.Logger {
return stdoutLogger
}

debugLogger = log.NewJSONLogger(debugLogWriter)
debugLogger = withFormat(viper.GetString("log-format"), debugLogWriter)
debugLogger = log.With(debugLogger, "ts", log.DefaultTimestampUTC)
debugLogger = log.With(debugLogger, "caller", fullPathCaller)
debugLogger = withLevel(debugLogger, "debug")
Expand All @@ -68,14 +69,14 @@ func New(v *viper.Viper, fs afero.Afero) log.Logger {
return realLogger
}

func withFormat(format string) log.Logger {
func withFormat(format string, w io.Writer) log.Logger {
switch format {
case "json":
return log.NewJSONLogger(os.Stdout)
return log.NewJSONLogger(w)
case "logfmt":
return log.NewLogfmtLogger(os.Stdout)
return log.NewLogfmtLogger(w)
default:
return log.NewLogfmtLogger(os.Stdout)
return log.NewLogfmtLogger(w)
}

}
Expand Down