diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-21 15:07:52 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-11-21 20:11:07 +0300 |
commit | 2dcc1318d1d9ed849d040115aa5ba6191a1c102a (patch) | |
tree | 913e5537df47c555a1d00e44d97609341edb36c3 /common | |
parent | 14a985f8abc527d4e8487fcd5fa742e1ab2a00ed (diff) |
Add some more output if loading modules takes time
Also include the time to collect modules etc. in the "Total in ..." time reported for the `hugo` command.
Fixes #6519
Diffstat (limited to 'common')
-rw-r--r-- | common/loggers/loggers.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/common/loggers/loggers.go b/common/loggers/loggers.go index 8766e6aaf..2b2ddb4d1 100644 --- a/common/loggers/loggers.go +++ b/common/loggers/loggers.go @@ -22,6 +22,7 @@ import ( "os" "regexp" "runtime" + "time" "github.com/gohugoio/hugo/common/terminal" @@ -41,6 +42,11 @@ func init() { // Logger wraps a *loggers.Logger and some other related logging state. type Logger struct { *jww.Notepad + + // The writer that represents stdout. + // Will be ioutil.Discard when in quiet mode. + Out io.Writer + ErrorCounter *jww.Counter WarnCounter *jww.Counter @@ -48,6 +54,23 @@ type Logger struct { errors *bytes.Buffer } +// PrintTimerIfDelayed prints a time statement to the FEEDBACK logger +// if considerable time is spent. +func (l *Logger) PrintTimerIfDelayed(start time.Time, name string) { + elapsed := time.Since(start) + milli := int(1000 * elapsed.Seconds()) + if milli < 500 { + return + } + l.FEEDBACK.Printf("%s in %v ms", name, milli) +} + +func (l *Logger) PrintTimer(start time.Time, name string) { + elapsed := time.Since(start) + milli := int(1000 * elapsed.Seconds()) + l.FEEDBACK.Printf("%s in %v ms", name, milli) +} + func (l *Logger) Errors() string { if l.errors == nil { return "" @@ -186,6 +209,7 @@ func newLogger(stdoutThreshold, logThreshold jww.Threshold, outHandle, logHandle return &Logger{ Notepad: jww.NewNotepad(stdoutThreshold, logThreshold, outHandle, logHandle, "", log.Ldate|log.Ltime, listeners...), + Out: outHandle, ErrorCounter: errorCounter, WarnCounter: warnCounter, errors: errorBuff, |