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
+28
View File
@@ -169,3 +169,31 @@ func TestJSONTimeKey(t *testing.T) {
t.Fatal("Expected JSON to format time key")
}
}
func TestJSONDisableTimestamp(t *testing.T) {
formatter := &JSONFormatter{
DisableTimestamp: true,
}
b, err := formatter.Format(WithField("level", "something"))
if err != nil {
t.Fatal("Unable to format entry: ", err)
}
s := string(b)
if strings.Contains(s, "time") {
t.Error("Did not prevent timestamp", s)
}
}
func TestJSONEnableTimestamp(t *testing.T) {
formatter := &JSONFormatter{}
b, err := formatter.Format(WithField("level", "something"))
if err != nil {
t.Fatal("Unable to format entry: ", err)
}
s := string(b)
if !strings.Contains(s, "time") {
t.Error("Timestamp not present", s)
}
}