-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_utc.go
35 lines (27 loc) · 882 Bytes
/
option_utc.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 withUTCTimestamp bool
func (w withUTCTimestamp) applySyslog(l *syslogLogger) error {
l.flags.enable(log.LUTC, bool(w))
return nil
}
func (w withUTCTimestamp) applyStdLog(l *stdLogger) error {
l.flags.enable(log.LUTC, bool(w))
return nil
}
// WithUTCTimestamp specifies whether loggers are to log timestamp in UTC.
func WithUTCTimestamp(enable bool) Option {
return withUTCTimestamp(enable)
}
// WithUTCTimestampFromEnv makes a WithUTCTimestamp option based on the specified environment variable env or
// defaultEnable if no environment variable was found.
func WithUTCTimestampFromEnv(env string, defaultEnable bool) OptionLoader {
return func() (Option, error) {
enable, err := boolFromEnv(env, defaultEnable)
if err != nil {
return nil, err
}
return withUTCTimestamp(enable), nil
}
}
var _ Option = withUTCTimestamp(false)