Add some color to the relevant filenames in terminal log

Fixes #5344
This commit is contained in:
Bjørn Erik Pedersen
2018-10-24 11:14:51 +02:00
parent 889aca054a
commit deff9e154b
4 changed files with 79 additions and 1 deletions

View File

@@ -19,6 +19,9 @@ import (
"io/ioutil"
"log"
"os"
"regexp"
"github.com/gohugoio/hugo/common/terminal"
jww "github.com/spf13/jwalterweatherman"
)
@@ -70,8 +73,22 @@ func NewErrorLogger() *Logger {
return newBasicLogger(jww.LevelError)
}
var ansiColorRe = regexp.MustCompile("(?s)\\033\\[\\d*(;\\d*)*m")
type ansiCleaner struct {
w io.Writer
}
func (a ansiCleaner) Write(p []byte) (n int, err error) {
return a.w.Write(ansiColorRe.ReplaceAll(p, []byte("")))
}
func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger {
errorCounter := &jww.Counter{}
if logHandle != ioutil.Discard && terminal.IsTerminal(os.Stdout) {
// Remove any Ansi coloring from log output
logHandle = ansiCleaner{w: logHandle}
}
listeners := []jww.LogListener{jww.LogCounter(errorCounter, jww.LevelError)}
var errorBuff *bytes.Buffer
if saveErrors {