Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The default backend was printing the date and time before the message #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package logging
import (
"bytes"
"fmt"
"log"
"os"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
12 changes: 6 additions & 6 deletions memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions multi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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) {
Expand Down