Skip to content
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
9 changes: 5 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ var (
// Sequence number is incremented and utilized for all log records created.
sequenceNo uint64

// timeNow is a customizable for testing purposes.
timeNow = time.Now
// TimeNow is is made public to allow to be set external.
TimeNow = time.Now

)

// Record represents a log record and contains the timestamp when the record
Expand Down Expand Up @@ -132,7 +133,7 @@ func Reset() {
b := SetBackend(NewLogBackend(os.Stderr, "", log.LstdFlags))
b.SetLevel(DEBUG, "")
SetFormatter(DefaultFormatter)
timeNow = time.Now
TimeNow = time.Now
}

// IsEnabledFor returns true if the logger is enabled for the given level.
Expand All @@ -148,7 +149,7 @@ func (l *Logger) log(lvl Level, format *string, args ...interface{}) {
// Create the logging record and pass it in to the backend
record := &Record{
ID: atomic.AddUint64(&sequenceNo, 1),
Time: timeNow(),
Time: TimeNow(),
Module: l.Module,
Level: lvl,
fmt: format,
Expand Down
2 changes: 1 addition & 1 deletion memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func InitForTesting(level Level) *MemoryBackend {
leveledBackend.SetLevel(level, "")
SetBackend(leveledBackend)

timeNow = func() time.Time {
TimeNow = func() time.Time {
return time.Unix(0, 0).UTC()
}
return memoryBackend
Expand Down