MCPcopy
hub / github.com/uber-go/zap / Write

Method Write

zapcore/entry.go:246–293  ·  view source on GitHub ↗

Write writes the entry to the stored Cores, returns any errors, and returns the CheckedEntry reference to a pool for immediate re-use. Finally, it executes any required CheckWriteAction.

(fields ...Field)

Source from the content-addressed store, hash-verified

244// the CheckedEntry reference to a pool for immediate re-use. Finally, it
245// executes any required CheckWriteAction.
246func (ce *CheckedEntry) Write(fields ...Field) {
247 if ce == nil {
248 return
249 }
250
251 if ce.dirty {
252 if ce.ErrorOutput != nil {
253 // Make a best effort to detect unsafe re-use of this CheckedEntry.
254 // If the entry is dirty, log an internal error; because the
255 // CheckedEntry is being used after it was returned to the pool,
256 // the message may be an amalgamation from multiple call sites.
257 _, _ = fmt.Fprintf(
258 ce.ErrorOutput,
259 "%v Unsafe CheckedEntry re-use near Entry %+v.\n",
260 ce.Time,
261 ce.Entry,
262 )
263 _ = ce.ErrorOutput.Sync() // ignore error
264 }
265 return
266 }
267 ce.dirty = true
268
269 ent := ce.Entry
270 for i := range ce.before {
271 ent, fields = ce.before[i](ent, fields)
272 }
273
274 var err error
275 for i := range ce.cores {
276 err = multierr.Append(err, ce.cores[i].Write(ent, fields))
277 }
278 if err != nil && ce.ErrorOutput != nil {
279 _, _ = fmt.Fprintf(
280 ce.ErrorOutput,
281 "%v write error: %v\n",
282 ce.Time,
283 err,
284 )
285 _ = ce.ErrorOutput.Sync() // ignore error
286 }
287
288 hook := ce.after
289 if hook != nil {
290 hook.OnWrite(ce, fields)
291 }
292 putCheckedEntry(ce)
293}
294
295// AddCore adds a Core that has agreed to log this CheckedEntry. It's intended to be
296// used by Core.Check implementations, and is safe to call on nil CheckedEntry

Callers 2

TestCheckedEntryWriteFunction · 0.95
TestCheckedEntryBeforeFunction · 0.95

Calls 4

putCheckedEntryFunction · 0.85
SyncMethod · 0.65
WriteMethod · 0.65
OnWriteMethod · 0.65

Tested by 2

TestCheckedEntryWriteFunction · 0.76
TestCheckedEntryBeforeFunction · 0.76