-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_microseconds.go
35 lines (27 loc) · 1020 Bytes
/
option_microseconds.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
35
package log
import "log"
type withMicrosecondsTimestamp bool
func (w withMicrosecondsTimestamp) applySyslog(l *syslogLogger) error {
l.flags.enable(log.Lmicroseconds, bool(w))
return nil
}
func (w withMicrosecondsTimestamp) applyStdLog(l *stdLogger) error {
l.flags.enable(log.Lmicroseconds, bool(w))
return nil
}
// WithMicrosecondsTimestamp specifies whether loggers are to log timestamp with microseconds precision.
func WithMicrosecondsTimestamp(enable bool) Option {
return withMicrosecondsTimestamp(enable)
}
// WithMicrosecondsTimestampFromEnv makes a WithMicrosecondsTimestamp option based on the specified environment variable
// env or defaultEnable if no environment variable was found.
func WithMicrosecondsTimestampFromEnv(env string, defaultEnable bool) OptionLoader {
return func() (Option, error) {
enable, err := boolFromEnv(env, defaultEnable)
if err != nil {
return nil, err
}
return withMicrosecondsTimestamp(enable), nil
}
}
var _ Option = withMicrosecondsTimestamp(false)