diff --git a/example_test.go b/example_test.go index deb8900..172e6d5 100644 --- a/example_test.go +++ b/example_test.go @@ -34,7 +34,7 @@ func Example() { log.Error("error") // Output: - // debug arg - // error + // 1970-01-01 00:00:00 debug arg + // 1970-01-01 00:00:00 error // 00:00:00.000 Example E error } diff --git a/format.go b/format.go index 99b1ddb..69475f7 100644 --- a/format.go +++ b/format.go @@ -114,8 +114,8 @@ func getFormatter() Formatter { } var ( - // DefaultFormatter is the default formatter used and is only the message. - DefaultFormatter Formatter = MustStringFormatter("%{message}") + // DefaultFormatter is the default formatter used and is the date, time and the message. + DefaultFormatter Formatter = MustStringFormatter("%{time:2006-01-02 15:04:05.999} %{message}") // Glog format GlogFormatter Formatter = MustStringFormatter("%{level:.1s}%{time:0102 15:04:05.999999} %{pid} %{shortfile}] %{message}") diff --git a/format_test.go b/format_test.go index c008e9e..092e46e 100644 --- a/format_test.go +++ b/format_test.go @@ -156,7 +156,7 @@ func TestBackendFormatter(t *testing.T) { log := MustGetLogger("module") log.Info("foo") - if "foo" != getLastLine(b1) { + if "1970-01-01 00:00:00 foo" != getLastLine(b1) { t.Errorf("Unexpected line: %s", getLastLine(b1)) } if "INFO foo" != getLastLine(b2) { diff --git a/logger.go b/logger.go index b3a57a8..73f72c8 100644 --- a/logger.go +++ b/logger.go @@ -10,7 +10,6 @@ package logging import ( "bytes" "fmt" - "log" "os" "strings" "sync/atomic" @@ -111,7 +110,7 @@ func Reset() { // if there's no backends at all configured, we could use some tricks to // automatically setup backends based if we have a TTY or not. sequenceNo = 0 - b := SetBackend(NewLogBackend(os.Stderr, "", log.LstdFlags)) + b := SetBackend(NewLogBackend(os.Stderr, "", 0)) b.SetLevel(DEBUG, "") SetFormatter(DefaultFormatter) timeNow = time.Now diff --git a/logger_test.go b/logger_test.go index acf2498..a43e928 100644 --- a/logger_test.go +++ b/logger_test.go @@ -30,7 +30,7 @@ func TestRedact(t *testing.T) { password := Password("123456") log := MustGetLogger("test") log.Debug("foo %s", password) - if "foo ******" != MemoryRecordN(backend, 0).Formatted(0) { + if "1970-01-01 00:00:00 foo ******" != MemoryRecordN(backend, 0).Formatted(0) { t.Errorf("redacted line: %v", MemoryRecordN(backend, 0)) } } diff --git a/memory_test.go b/memory_test.go index fe5a82e..301f1e9 100644 --- a/memory_test.go +++ b/memory_test.go @@ -58,17 +58,17 @@ func TestMemoryBackend(t *testing.T) { t.Errorf("record length: %d", backend.size) } record := MemoryRecordN(backend, 0) - if "5" != record.Formatted(0) { + if "1970-01-01 00:00:00 5" != record.Formatted(0) { t.Errorf("unexpected start: %s", record.Formatted(0)) } for i := 0; i < 8; i++ { record = MemoryRecordN(backend, i) - if strconv.Itoa(i+5) != record.Formatted(0) { + if "1970-01-01 00:00:00 " + strconv.Itoa(i+5) != record.Formatted(0) { t.Errorf("unexpected record: %v", record.Formatted(0)) } } record = MemoryRecordN(backend, 7) - if "12" != record.Formatted(0) { + if "1970-01-01 00:00:00 12" != record.Formatted(0) { t.Errorf("unexpected end: %s", record.Formatted(0)) } record = MemoryRecordN(backend, 8) @@ -97,17 +97,17 @@ func TestChannelMemoryBackend(t *testing.T) { t.Errorf("record length: %d", backend.size) } record := ChannelMemoryRecordN(backend, 0) - if "5" != record.Formatted(0) { + if "1970-01-01 00:00:00 5" != record.Formatted(0) { t.Errorf("unexpected start: %s", record.Formatted(0)) } for i := 0; i < 8; i++ { record = ChannelMemoryRecordN(backend, i) - if strconv.Itoa(i+5) != record.Formatted(0) { + if "1970-01-01 00:00:00 " + strconv.Itoa(i+5) != record.Formatted(0) { t.Errorf("unexpected record: %v", record.Formatted(0)) } } record = ChannelMemoryRecordN(backend, 7) - if "12" != record.Formatted(0) { + if "1970-01-01 00:00:00 12" != record.Formatted(0) { t.Errorf("unexpected end: %s", record.Formatted(0)) } record = ChannelMemoryRecordN(backend, 8) diff --git a/multi_test.go b/multi_test.go index b6ecf5b..54602c5 100644 --- a/multi_test.go +++ b/multi_test.go @@ -14,10 +14,10 @@ func TestMultiLogger(t *testing.T) { log := MustGetLogger("test") log.Debug("log") - if "log" != MemoryRecordN(log1, 0).Formatted(0) { + if "1970-01-01 00:00:00 log" != MemoryRecordN(log1, 0).Formatted(0) { t.Errorf("log1: %v", MemoryRecordN(log1, 0).Formatted(0)) } - if "log" != MemoryRecordN(log2, 0).Formatted(0) { + if "1970-01-01 00:00:00 log" != MemoryRecordN(log2, 0).Formatted(0) { t.Errorf("log2: %v", MemoryRecordN(log2, 0).Formatted(0)) } } @@ -42,7 +42,7 @@ func TestMultiLoggerLevel(t *testing.T) { leveled1.SetLevel(DEBUG, "test") log.Notice("log") - if "log" != MemoryRecordN(log1, 0).Formatted(0) { + if "1970-01-01 00:00:00 log" != MemoryRecordN(log1, 0).Formatted(0) { t.Errorf("log1 not receieved") } if nil != MemoryRecordN(log2, 0) {