mirror of
https://github.com/caddyserver/caddy.git
synced 2025-06-09 14:46:39 +08:00
logging: Customizable zap cores (#6381)
This commit is contained in:
12
logging.go
12
logging.go
@ -292,6 +292,10 @@ type BaseLog struct {
|
||||
// The encoder is how the log entries are formatted or encoded.
|
||||
EncoderRaw json.RawMessage `json:"encoder,omitempty" caddy:"namespace=caddy.logging.encoders inline_key=format"`
|
||||
|
||||
// Tees entries through a zap.Core module which can extract
|
||||
// log entry metadata and fields for further processing.
|
||||
CoreRaw json.RawMessage `json:"core,omitempty" caddy:"namespace=caddy.logging.cores inline_key=module"`
|
||||
|
||||
// Level is the minimum level to emit, and is inclusive.
|
||||
// Possible levels: DEBUG, INFO, WARN, ERROR, PANIC, and FATAL
|
||||
Level string `json:"level,omitempty"`
|
||||
@ -366,6 +370,14 @@ func (cl *BaseLog) provisionCommon(ctx Context, logging *Logging) error {
|
||||
cl.encoder = newDefaultProductionLogEncoder(cl.writerOpener)
|
||||
}
|
||||
cl.buildCore()
|
||||
if cl.CoreRaw != nil {
|
||||
mod, err := ctx.LoadModule(cl, "CoreRaw")
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading log core module: %v", err)
|
||||
}
|
||||
core := mod.(zapcore.Core)
|
||||
cl.core = zapcore.NewTee(cl.core, core)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user