-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.go
34 lines (29 loc) · 957 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package alog
import (
"time"
)
// Option sets an option on a Logger.
//
// Options are applied in the order specified, meaning if both To and
// WithEmitter are supplied in a call to New, the last one wins.
type Option func(*Logger)
// WithEmitter configures the logger to call e.Emit() every time it needs to
// emit a log line.
//
// Calls are not synchronized.
func WithEmitter(e Emitter) Option {
return func(l *Logger) { l.emitter = e }
}
// WithCaller configures the logger to include the caller information in each
// log entry.
func WithCaller() Option {
return func(l *Logger) { l.caller = true }
}
// OverrideTimestamp sets the function that will be used to get the current
// time for each log entry.
//
// This is primarily meant to be used for testing custom emitters.
// For example: OverrideTimestamp(func() time.Time { return time.Time{} })
func OverrideTimestamp(f func() time.Time) Option {
return func(l *Logger) { l.now = f }
}