aboutsummaryrefslogtreecommitdiffhomepage
path: root/logger
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2019-06-08 17:16:12 -0700
committerGravatar fguillot <fred@miniflux.net>2019-06-08 17:48:45 -0700
commit91508c50b54c9a0375856a17b2e774d42782b81d (patch)
tree995936a1bf95f1d31da8841e6aef655ffa38f75b /logger
parentf7b7b63e3f30b4d855a26d550ddf726116c65846 (diff)
Add option to toggle date/time in log messages
Diffstat (limited to 'logger')
-rw-r--r--logger/logger.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/logger/logger.go b/logger/logger.go
index a430c0d..f329b2c 100644
--- a/logger/logger.go
+++ b/logger/logger.go
@@ -7,9 +7,11 @@ package logger // import "miniflux.app/logger"
import (
"fmt"
"os"
+ "time"
)
var requestedLevel = InfoLevel
+var displayDateTime = false
// LogLevel type.
type LogLevel uint32
@@ -43,6 +45,11 @@ func (level LogLevel) String() string {
}
}
+// EnableDateTime enables date time in log messages.
+func EnableDateTime() {
+ displayDateTime = true
+}
+
// EnableDebug increases logging, more verbose (debug)
func EnableDebug() {
requestedLevel = DebugLevel
@@ -79,6 +86,13 @@ func Fatal(format string, v ...interface{}) {
}
func formatMessage(level LogLevel, format string, v ...interface{}) {
- prefix := fmt.Sprintf("[%s] ", level.String())
+ var prefix string
+
+ if displayDateTime {
+ prefix = fmt.Sprintf("[%s] [%s] ", time.Now().Format("2006-01-02T15:04:05"), level)
+ } else {
+ prefix = fmt.Sprintf("[%s] ", level)
+ }
+
fmt.Fprintf(os.Stderr, prefix+format+"\n", v...)
}