@@ -41,11 +41,9 @@ func New(opts ...Opts) logr.Logger {
41
41
// (stacktraces on warnings, no sampling), otherwise a Zap production
42
42
// config will be used (stacktraces on errors, sampling).
43
43
//
44
- // Deprecated, use New() and the functional opts pattern instead:
44
+ // Deprecated: use New() and the functional opts pattern instead:
45
45
//
46
- // New(func(o *Options){
47
- // o.Development = development
48
- // })
46
+ // New(UseDevMode(development))
49
47
func Logger (development bool ) logr.Logger {
50
48
return LoggerTo (os .Stderr , development )
51
49
}
@@ -54,9 +52,9 @@ func Logger(development bool) logr.Logger {
54
52
// to the given destination, instead of stderr. It otherwise behaves like
55
53
// ZapLogger.
56
54
//
57
- // Deprecated, use New() and the functional opts pattern instead:
55
+ // Deprecated: use New() and the functional opts pattern instead:
58
56
//
59
- // New(func(o *Options){
57
+ // New(UseDevMode(development), WriteTo(writer))
60
58
// o.Development = development
61
59
// o.DestWriter = writer
62
60
// })
@@ -67,11 +65,9 @@ func LoggerTo(destWriter io.Writer, development bool) logr.Logger {
67
65
// RawLoggerTo returns a new zap.Logger configured with KubeAwareEncoder
68
66
// which logs to a given destination
69
67
//
70
- // Deprecated, use NewRaw() and the functional opts pattern instead:
68
+ // Deprecated: use NewRaw() and the functional opts pattern instead:
71
69
//
72
- // NewRaw(func(o *Options){
73
- // o.Development = development
74
- // })
70
+ // NewRaw(UseDevMode(development))
75
71
func RawLoggerTo (destWriter io.Writer , development bool , opts ... zap.Option ) * zap.Logger {
76
72
o := func (o * Options ) {
77
73
o .DestWritter = destWriter
@@ -84,25 +80,44 @@ func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *za
84
80
// Opts allows to manipulate Options
85
81
type Opts func (* Options )
86
82
83
+ // UseDevMode sets the logger to use (or not use) development mode (more
84
+ // human-readable output, extra stack traces and logging information, etc).
85
+ // See Options.Development
86
+ func UseDevMode (enabled bool ) Opts {
87
+ return func (o * Options ) {
88
+ o .Development = true
89
+ }
90
+ }
91
+
92
+ // WriteTo configures the logger to write to the given io.Writer, instead of standard error.
93
+ // See Options.WriterTo.
94
+ func WriteTo (out io.Writer ) Opts {
95
+ return func (o * Options ) {
96
+ o .DestWritter = out
97
+ }
98
+ }
99
+
87
100
// Options contains all possible settings
88
101
type Options struct {
89
- // If Development is true, a Zap development config will be used
102
+ // Development configures the logger to use a Zap development config
90
103
// (stacktraces on warnings, no sampling), otherwise a Zap production
91
104
// config will be used (stacktraces on errors, sampling).
92
105
Development bool
93
- // The encoder to use, defaults to console when Development is true
94
- // and JSON otherwise
106
+ // Encoder configures how Zap will encode the output. Defaults to
107
+ // console when Development is true and JSON otherwise
95
108
Encoder zapcore.Encoder
96
- // The destination to write to, defaults to os.Stderr
109
+ // DestWritter controls the destination of the log output. Defaults to
110
+ // os.Stderr.
97
111
DestWritter io.Writer
98
- // The level to use, defaults to Debug when Development is true and
99
- // Info otherwise
112
+ // Level configures the verbosity of the logging. Defaults to Debug when
113
+ // Development is true and Info otherwise
100
114
Level * zap.AtomicLevel
101
115
// StacktraceLevel is the level at and above which stacktraces will
102
116
// be recorded for all messages. Defaults to Warn when Development
103
117
// is true and Error otherwise
104
118
StacktraceLevel * zap.AtomicLevel
105
- // Raw zap.Options to configure on the underlying zap logger
119
+ // ZapOpts allows passing arbitrary zap.Options to configure on the
120
+ // underlying Zap logger.
106
121
ZapOpts []zap.Option
107
122
}
108
123
0 commit comments