-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
72 lines (52 loc) · 1.5 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package zerolog
import (
"github.com/rs/zerolog"
"go.unistack.org/micro/v3/logger"
)
type Options struct {
logger.Options
// Flag for whether to log caller info (off by default)
ReportCaller bool
// Use this logger as system wide default logger (off by default)
UseAsDefault bool
// zerolog hooks
Hooks []zerolog.Hook
// TimeFormat is one of time.RFC3339, time.RFC3339Nano, time.*
TimeFormat string
// Runtime mode. (Production by default)
Mode Mode
// Exit Function to call when FatalLevel log
ExitFunc func(int)
}
type reportCallerKey struct{}
func ReportCaller() logger.Option {
return logger.SetOption(reportCallerKey{}, true)
}
type useAsDefaultKey struct{}
func UseAsDefault() logger.Option {
return logger.SetOption(useAsDefaultKey{}, true)
}
type developmentModeKey struct{}
func WithDevelopmentMode() logger.Option {
return logger.SetOption(developmentModeKey{}, true)
}
type productionModeKey struct{}
func WithProductionMode() logger.Option {
return logger.SetOption(productionModeKey{}, true)
}
type timeFormatKey struct{}
func WithTimeFormat(timeFormat string) logger.Option {
return logger.SetOption(timeFormatKey{}, timeFormat)
}
type hooksKey struct{}
func WithHooks(hooks []zerolog.Hook) logger.Option {
return logger.SetOption(hooksKey{}, hooks)
}
type exitKey struct{}
func WithExitFunc(exit func(int)) logger.Option {
return logger.SetOption(exitKey{}, exit)
}
type loggerKey struct{}
func WithLogger(l logger.Logger) logger.Option {
return logger.SetOption(loggerKey{}, l)
}