Skip to content

Commit c73f47f

Browse files
author
Justin Reagor
committed
Introduce configurable timestamp format ala Logrus practices
1 parent 9f2c7bc commit c73f47f

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

config/logger/logging.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func (l *Config) Init() error {
5959
case "json":
6060
formatter = &logrus.JSONFormatter{}
6161
case "default":
62-
formatter = &DefaultLogFormatter{}
62+
formatter = &DefaultLogFormatter{
63+
TimestampFormat: time.RFC3339Nano,
64+
}
6365
default:
6466
return fmt.Errorf("Unknown log format '%s'", l.Format)
6567
}
@@ -86,13 +88,14 @@ func (l *Config) Init() error {
8688

8789
// DefaultLogFormatter delegates formatting to standard go log package
8890
type DefaultLogFormatter struct {
91+
TimestampFormat string
8992
}
9093

9194
// Format formats the logrus entry by passing it to the "log" package
9295
func (f *DefaultLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
9396
b := &bytes.Buffer{}
9497
logger := log.New(b, "", 0)
95-
logger.Println(time.Now().Format(time.RFC3339Nano) + " " + string(entry.Message))
98+
logger.Println(time.Now().Format(f.TimestampFormat) + " " + string(entry.Message))
9699
// Panic and Fatal are handled by logrus automatically
97100
return b.Bytes(), nil
98101
}

0 commit comments

Comments
 (0)