@@ -25,15 +25,15 @@ import (
25
25
// loggerPromise knows how to populate a concrete logr.Logger
26
26
// with options, given an actual base logger later on down the line.
27
27
type loggerPromise struct {
28
- logger * DelegatingLogSink
28
+ logger * delegatingLogSink
29
29
childPromises []* loggerPromise
30
30
promisesLock sync.Mutex
31
31
32
32
name * string
33
33
tags []interface {}
34
34
}
35
35
36
- func (p * loggerPromise ) WithName (l * DelegatingLogSink , name string ) * loggerPromise {
36
+ func (p * loggerPromise ) WithName (l * delegatingLogSink , name string ) * loggerPromise {
37
37
res := & loggerPromise {
38
38
logger : l ,
39
39
name : & name ,
@@ -47,7 +47,7 @@ func (p *loggerPromise) WithName(l *DelegatingLogSink, name string) *loggerPromi
47
47
}
48
48
49
49
// WithValues provides a new Logger with the tags appended.
50
- func (p * loggerPromise ) WithValues (l * DelegatingLogSink , tags ... interface {}) * loggerPromise {
50
+ func (p * loggerPromise ) WithValues (l * delegatingLogSink , tags ... interface {}) * loggerPromise {
51
51
res := & loggerPromise {
52
52
logger : l ,
53
53
tags : tags ,
@@ -84,20 +84,21 @@ func (p *loggerPromise) Fulfill(parentLogSink logr.LogSink) {
84
84
}
85
85
}
86
86
87
- // DelegatingLogSink is a logsink that delegates to another logr.LogSink.
87
+ // delegatingLogSink is a logsink that delegates to another logr.LogSink.
88
88
// If the underlying promise is not nil, it registers calls to sub-loggers with
89
89
// the logging factory to be populated later, and returns a new delegating
90
90
// logger. It expects to have *some* logr.Logger set at all times (generally
91
91
// a no-op logger before the promises are fulfilled).
92
- type DelegatingLogSink struct {
92
+ type delegatingLogSink struct {
93
93
lock sync.RWMutex
94
94
logger logr.LogSink
95
95
promise * loggerPromise
96
96
info logr.RuntimeInfo
97
97
}
98
98
99
99
// Init implements logr.LogSink.
100
- func (l * DelegatingLogSink ) Init (info logr.RuntimeInfo ) {
100
+ func (l * delegatingLogSink ) Init (info logr.RuntimeInfo ) {
101
+ eventuallyFulfillRoot ()
101
102
l .lock .Lock ()
102
103
defer l .lock .Unlock ()
103
104
l .info = info
@@ -106,7 +107,8 @@ func (l *DelegatingLogSink) Init(info logr.RuntimeInfo) {
106
107
// Enabled tests whether this Logger is enabled. For example, commandline
107
108
// flags might be used to set the logging verbosity and disable some info
108
109
// logs.
109
- func (l * DelegatingLogSink ) Enabled (level int ) bool {
110
+ func (l * delegatingLogSink ) Enabled (level int ) bool {
111
+ eventuallyFulfillRoot ()
110
112
l .lock .RLock ()
111
113
defer l .lock .RUnlock ()
112
114
return l .logger .Enabled (level )
@@ -118,7 +120,8 @@ func (l *DelegatingLogSink) Enabled(level int) bool {
118
120
// the log line. The key/value pairs can then be used to add additional
119
121
// variable information. The key/value pairs should alternate string
120
122
// keys and arbitrary values.
121
- func (l * DelegatingLogSink ) Info (level int , msg string , keysAndValues ... interface {}) {
123
+ func (l * delegatingLogSink ) Info (level int , msg string , keysAndValues ... interface {}) {
124
+ eventuallyFulfillRoot ()
122
125
l .lock .RLock ()
123
126
defer l .lock .RUnlock ()
124
127
l .logger .Info (level , msg , keysAndValues ... )
@@ -132,14 +135,16 @@ func (l *DelegatingLogSink) Info(level int, msg string, keysAndValues ...interfa
132
135
// The msg field should be used to add context to any underlying error,
133
136
// while the err field should be used to attach the actual error that
134
137
// triggered this log line, if present.
135
- func (l * DelegatingLogSink ) Error (err error , msg string , keysAndValues ... interface {}) {
138
+ func (l * delegatingLogSink ) Error (err error , msg string , keysAndValues ... interface {}) {
139
+ eventuallyFulfillRoot ()
136
140
l .lock .RLock ()
137
141
defer l .lock .RUnlock ()
138
142
l .logger .Error (err , msg , keysAndValues ... )
139
143
}
140
144
141
145
// WithName provides a new Logger with the name appended.
142
- func (l * DelegatingLogSink ) WithName (name string ) logr.LogSink {
146
+ func (l * delegatingLogSink ) WithName (name string ) logr.LogSink {
147
+ eventuallyFulfillRoot ()
143
148
l .lock .RLock ()
144
149
defer l .lock .RUnlock ()
145
150
@@ -151,15 +156,16 @@ func (l *DelegatingLogSink) WithName(name string) logr.LogSink {
151
156
return sink
152
157
}
153
158
154
- res := & DelegatingLogSink {logger : l .logger }
159
+ res := & delegatingLogSink {logger : l .logger }
155
160
promise := l .promise .WithName (res , name )
156
161
res .promise = promise
157
162
158
163
return res
159
164
}
160
165
161
166
// WithValues provides a new Logger with the tags appended.
162
- func (l * DelegatingLogSink ) WithValues (tags ... interface {}) logr.LogSink {
167
+ func (l * delegatingLogSink ) WithValues (tags ... interface {}) logr.LogSink {
168
+ eventuallyFulfillRoot ()
163
169
l .lock .RLock ()
164
170
defer l .lock .RUnlock ()
165
171
@@ -171,7 +177,7 @@ func (l *DelegatingLogSink) WithValues(tags ...interface{}) logr.LogSink {
171
177
return sink
172
178
}
173
179
174
- res := & DelegatingLogSink {logger : l .logger }
180
+ res := & delegatingLogSink {logger : l .logger }
175
181
promise := l .promise .WithValues (res , tags ... )
176
182
res .promise = promise
177
183
@@ -181,16 +187,16 @@ func (l *DelegatingLogSink) WithValues(tags ...interface{}) logr.LogSink {
181
187
// Fulfill switches the logger over to use the actual logger
182
188
// provided, instead of the temporary initial one, if this method
183
189
// has not been previously called.
184
- func (l * DelegatingLogSink ) Fulfill (actual logr.LogSink ) {
190
+ func (l * delegatingLogSink ) Fulfill (actual logr.LogSink ) {
185
191
if l .promise != nil {
186
192
l .promise .Fulfill (actual )
187
193
}
188
194
}
189
195
190
- // NewDelegatingLogSink constructs a new DelegatingLogSink which uses
196
+ // newDelegatingLogSink constructs a new DelegatingLogSink which uses
191
197
// the given logger before its promise is fulfilled.
192
- func NewDelegatingLogSink (initial logr.LogSink ) * DelegatingLogSink {
193
- l := & DelegatingLogSink {
198
+ func newDelegatingLogSink (initial logr.LogSink ) * delegatingLogSink {
199
+ l := & delegatingLogSink {
194
200
logger : initial ,
195
201
promise : & loggerPromise {promisesLock : sync.Mutex {}},
196
202
}
0 commit comments