diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-10-28 16:06:50 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-10-28 16:06:50 +0100 |
commit | 9c88a8a55adf7779039504fa77d74ec80d658c40 (patch) | |
tree | cd50453b4a2d3dd64e876afcedf42eed2a81a51b /common | |
parent | 95e72f5e8e4634fbbb2ea7ece2156487230ad1d4 (diff) | |
download | hugo-9c88a8a55adf7779039504fa77d74ec80d658c40.tar.gz hugo-9c88a8a55adf7779039504fa77d74ec80d658c40.zip |
common/loggers: Make sure the global logger also gets colored labels
See #4414
Diffstat (limited to 'common')
-rw-r--r-- | common/loggers/loggers.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/common/loggers/loggers.go b/common/loggers/loggers.go index 37f50a6c0..0a9c7da68 100644 --- a/common/loggers/loggers.go +++ b/common/loggers/loggers.go @@ -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 { |