diff --git a/common/loggers/loggers.go b/common/loggers/loggers.go index 082fd1487..8766e6aaf 100644 --- a/common/loggers/loggers.go +++ b/common/loggers/loggers.go @@ -15,11 +15,13 @@ package loggers import ( "bytes" + "fmt" "io" "io/ioutil" "log" "os" "regexp" + "runtime" "github.com/gohugoio/hugo/common/terminal" @@ -142,6 +144,26 @@ func getLogWriters(outHandle, logHandle io.Writer) (io.Writer, io.Writer) { } +type fatalLogWriter int + +func (s fatalLogWriter) Write(p []byte) (n int, err error) { + trace := make([]byte, 1500) + runtime.Stack(trace, true) + fmt.Printf("\n===========\n\n%s\n", trace) + os.Exit(-1) + + return 0, nil +} + +var fatalLogListener = func(t jww.Threshold) io.Writer { + if t != jww.LevelError { + // Only interested in ERROR + return nil + } + + return new(fatalLogWriter) +} + func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle io.Writer, saveErrors bool) *Logger { errorCounter := &jww.Counter{} warnCounter := &jww.Counter{} @@ -156,7 +178,6 @@ func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle // Only interested in ERROR return nil } - return errorBuff } diff --git a/go.mod b/go.mod index 795481329..9e22be9f7 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/PuerkitoBio/purell v1.1.0 github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/alecthomas/chroma v0.6.7 + github.com/alecthomas/chroma v0.6.8 github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 // indirect github.com/armon/go-radix v1.0.0 github.com/aws/aws-sdk-go v1.19.40 diff --git a/go.sum b/go.sum index e82914081..6e7df89f7 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= github.com/alecthomas/chroma v0.6.7 h1:1hKci+AyKOxJrugR9veaocu9DQGR2/GecI72BpaO0Rg= github.com/alecthomas/chroma v0.6.7/go.mod h1:zVlgtbRS7BJDrDY9SB238RmpoCBCYFlLmcfZ3durxTk= +github.com/alecthomas/chroma v0.6.8 h1:TW4JJaIdbAbMyUtGEd6BukFlOKYvVQz3vVhLBEUNwMU= +github.com/alecthomas/chroma v0.6.8/go.mod h1:o9ohftueRi7H5be3+Q2cQCNa/YnLBFUNx40ZJfGVFKA= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= diff --git a/helpers/pygments.go b/helpers/pygments.go index 0fe1e7592..4d7631ced 100644 --- a/helpers/pygments.go +++ b/helpers/pygments.go @@ -82,7 +82,7 @@ func (h highlighters) chromaHighlight(code, lang, optsStr string) (string, error err = chromaHighlight(b, code, lang, style, f) if err != nil { - jww.ERROR.Print(err.Error()) + jww.ERROR.Printf("Highlight failed: %s\nLang: %q\nCode: \n%s", err, lang, code) return code, err }