@@ -43,9 +43,7 @@ func New(opts ...Opts) logr.Logger {
43
43
//
44
44
// Deprecated, use New() and the functional opts pattern instead:
45
45
//
46
- // New(func(o *Options){
47
- // o.Development: development,
48
- // })
46
+ // New(Development(true))
49
47
func Logger (development bool ) logr.Logger {
50
48
return LoggerTo (os .Stderr , development )
51
49
}
@@ -56,10 +54,7 @@ func Logger(development bool) logr.Logger {
56
54
//
57
55
// Deprecated, use New() and the functional opts pattern instead:
58
56
//
59
- // New(func(o *Options){
60
- // o.Development: development,
61
- // o.DestWriter: writer,
62
- // })
57
+ // New(Development(development), DestWritter(destWriter))
63
58
func LoggerTo (destWriter io.Writer , development bool ) logr.Logger {
64
59
return zapr .NewLogger (RawLoggerTo (destWriter , development ))
65
60
}
@@ -69,16 +64,9 @@ func LoggerTo(destWriter io.Writer, development bool) logr.Logger {
69
64
//
70
65
// Deprecated, use NewRaw() and the functional opts pattern instead:
71
66
//
72
- // NewRaw(func(o *Options){
73
- // o.Development: development,
74
- // })
67
+ // NewRaw(Development(development), DestWritter(destWriter), ZapOpts(opts))
75
68
func RawLoggerTo (destWriter io.Writer , development bool , opts ... zap.Option ) * zap.Logger {
76
- o := func (o * Options ) {
77
- o .DestWritter = destWriter
78
- o .Development = development
79
- o .ZapOpts = opts
80
- }
81
- return NewRaw (o )
69
+ return NewRaw (Development (development ), DestWritter (destWriter ), ZapOpts (opts ))
82
70
}
83
71
84
72
// Opts allows to manipulate Options
@@ -149,6 +137,48 @@ func (o *Options) addDefaults() {
149
137
o .ZapOpts = append (o .ZapOpts , zap .AddStacktrace (o .StacktraceLevel ))
150
138
}
151
139
140
+ // Development sets the Development option for the logger
141
+ func Development (development bool ) func (o * Options ) {
142
+ return func (o * Options ) {
143
+ o .Development = development
144
+ }
145
+ }
146
+
147
+ // Encoder sets the Encoder option for the logger
148
+ func Encoder (encoder zapcore.Encoder ) func (o * Options ) {
149
+ return func (o * Options ) {
150
+ o .Encoder = encoder
151
+ }
152
+ }
153
+
154
+ // DestWritter sets the DestWritter option for the logger
155
+ func DestWritter (destWriter io.Writer ) func (o * Options ) {
156
+ return func (o * Options ) {
157
+ o .DestWritter = destWriter
158
+ }
159
+ }
160
+
161
+ // Level sets the Level option for the logger
162
+ func Level (level * zap.AtomicLevel ) func (o * Options ) {
163
+ return func (o * Options ) {
164
+ o .Level = level
165
+ }
166
+ }
167
+
168
+ // StacktraceLevel sets the StacktraceLevel option for the logger
169
+ func StacktraceLevel (stacktraceLevel * zap.AtomicLevel ) func (o * Options ) {
170
+ return func (o * Options ) {
171
+ o .StacktraceLevel = stacktraceLevel
172
+ }
173
+ }
174
+
175
+ // ZapOpts appends zapOpts to the raw zap.Options option of the logger
176
+ func ZapOpts (zapOpts []zap.Option ) func (o * Options ) {
177
+ return func (o * Options ) {
178
+ o .ZapOpts = append (o .ZapOpts , zapOpts ... )
179
+ }
180
+ }
181
+
152
182
// NewRaw returns a new zap.Logger configured with the passed Opts
153
183
// or their defaults. It uses KubeAwareEncoder which adds Type
154
184
// information and Namespace/Name to the log.
0 commit comments