Permalink
Browse files

common/loggers: Make sure the global logger also gets colored labels

See #4414
  • Loading branch information...
bep committed Oct 28, 2018
1 parent 95e72f5 commit 9c88a8a55adf7779039504fa77d74ec80d658c40
Showing with 24 additions and 7 deletions.
  1. +1 −4 commands/hugo.go
  2. +20 −2 common/loggers/loggers.go
  3. +1 −1 go.mod
  4. +2 −0 go.sum
@@ -162,10 +162,7 @@ func (c *commandeer) createLogger(cfg config.Provider, running bool) (*loggers.L
}
}
// The global logger is used in some few cases.
jww.SetLogOutput(logHandle)
jww.SetLogThreshold(logThreshold)
jww.SetStdoutThreshold(stdoutThreshold)
loggers.InitGlobalLogger(stdoutThreshold, logThreshold, outHandle, logHandle)
helpers.InitLoggers()
return loggers.NewLogger(stdoutThreshold, logThreshold, outHandle, logHandle, running), nil
@@ -115,9 +115,19 @@ func (a labelColorizer) Write(p []byte) (n int, err error) {
}
func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger {
// InitGlobalLogger initalizes the global logger, used in some rare cases.
func InitGlobalLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer) {
outHandle, logHandle = getLogWriters(outHandle, logHandle)
jww.SetStdoutOutput(outHandle)
jww.SetLogOutput(logHandle)
jww.SetLogThreshold(logThreshold)
jww.SetStdoutThreshold(stdoutThreshold)
}
func getLogWriters(outHandle, logHandle io.Writer) (io.Writer, io.Writer) {
isTerm := terminal.IsTerminal(os.Stdout)
errorCounter := &jww.Counter{}
if logHandle != ioutil.Discard && isTerm {
// Remove any Ansi coloring from log output
logHandle = ansiCleaner{w: logHandle}
@@ -127,6 +137,14 @@ func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle
outHandle = labelColorizer{w: outHandle}
}
return outHandle, logHandle
}
func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger {
errorCounter := &jww.Counter{}
outHandle, logHandle = getLogWriters(outHandle, logHandle)
listeners := []jww.LogListener{jww.LogCounter(errorCounter, jww.LevelError)}
var errorBuff *bytes.Buffer
if saveErrors {
2 go.mod

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
2 go.sum

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 9c88a8a

Please sign in to comment.