| 1100 | } |
| 1101 | |
| 1102 | func TestEventTimestamp(t *testing.T) { |
| 1103 | TimestampFunc = func() time.Time { |
| 1104 | return time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC) |
| 1105 | } |
| 1106 | defer func() { |
| 1107 | TimestampFunc = time.Now |
| 1108 | }() |
| 1109 | out := &bytes.Buffer{} |
| 1110 | log := New(out).With().Str("foo", "bar").Logger() |
| 1111 | log.Log().Timestamp().Msg("hello world") |
| 1112 | |
| 1113 | if got, want := decodeIfBinaryToString(out.Bytes()), `{"foo":"bar","time":"2001-02-03T04:05:06Z","message":"hello world"}`+"\n"; got != want { |
| 1114 | t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want) |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | func TestOutputWithoutTimestamp(t *testing.T) { |
| 1119 | ignoredOut := &bytes.Buffer{} |