Added option to disable JSON timestamp

Tests verify both the default and disabled case.
This commit is contained in:
Andrew Burian
2016-11-21 10:09:59 -08:00
parent a437dfd246
commit 1d329ad042
2 changed files with 34 additions and 1 deletions
+6 -1
View File
@@ -26,6 +26,9 @@ type JSONFormatter struct {
// TimestampFormat sets the format used for marshaling timestamps.
TimestampFormat string
// DisableTimestamp allows disabling automatic timestamps in output
DisableTimestamp bool
// FieldMap allows users to customize the names of keys for various fields.
// As an example:
// formatter := &JSONFormatter{
@@ -57,7 +60,9 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
timestampFormat = DefaultTimestampFormat
}
data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
if !f.DisableTimestamp {
data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
}
data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()