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
This commit is contained in:
Bjørn Erik Pedersen
2019-11-21 13:07:52 +01:00
parent 14a985f8ab
commit 2dcc1318d1
6 changed files with 55 additions and 12 deletions

View File

@@ -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,