| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otelcol |
| 5 |
|
| 6 |
import ( |
| 7 |
"sync/atomic" |
| 8 |
|
| 9 |
"go.uber.org/zap/zapcore" |
| 10 |
) |
| 11 |
|
| 12 |
var _ zapcore.Core = (*collectorCore)(nil) |
| 13 |
|
| 14 |
type collectorCore struct { |
| 15 |
delegate atomic.Pointer[zapcore.Core] |
| 16 |
} |
| 17 |
|
| 18 |
func newCollectorCore(core zapcore.Core) *collectorCore { |
| 19 |
cc := &collectorCore{} |
| 20 |
cc.SetCore(core) |
| 21 |
return cc |
| 22 |
} |
| 23 |
|
| 24 |
func (c *collectorCore) Enabled(l zapcore.Level) bool { |
| 25 |
return c.loadDelegate().Enabled(l) |
| 26 |
} |
| 27 |
|
| 28 |
func (c *collectorCore) With(f []zapcore.Field) zapcore.Core { |
| 29 |
return newCollectorCore(c.loadDelegate().With(f)) |
| 30 |
} |
| 31 |
|
| 32 |
func (c *collectorCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry { |
| 33 |
core := c.loadDelegate() |
| 34 |
if core.Enabled(e.Level) { |
| 35 |
return ce.AddCore(e, core) |
| 36 |
} |
| 37 |
return ce |
| 38 |
} |
| 39 |
|
| 40 |
func (c *collectorCore) Write(e zapcore.Entry, f []zapcore.Field) error { |
| 41 |
return c.loadDelegate().Write(e, f) |
| 42 |
} |
| 43 |
|
| 44 |
func (c *collectorCore) Sync() error { |
| 45 |
return c.loadDelegate().Sync() |
| 46 |
} |
| 47 |
|
| 48 |
func (c *collectorCore) SetCore(core zapcore.Core) { |
| 49 |
c.delegate.Store(&core) |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
func (c *collectorCore) loadDelegate() zapcore.Core { |
| 54 |
return *c.delegate.Load() |
| 55 |
} |