Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/loggers/loggers.go24
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,