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