aboutsummaryrefslogtreecommitdiffhomepage
path: root/logging.go
diff options
context:
space:
mode:
authorOmar Ramadan <[email protected]>2024-06-10 08:03:24 -0700
committerGitHub <[email protected]>2024-06-10 09:03:24 -0600
commitd85cc2ec103de72658c55ba74197337c99bd1f74 (patch)
tree3632039ef94eb0963568df76aa9f542cdf949552 /logging.go
parent04fb9fe87ff7406b36a4a7f0a9215ab7a138d345 (diff)
downloadcaddy-d85cc2ec103de72658c55ba74197337c99bd1f74.tar.gz
caddy-d85cc2ec103de72658c55ba74197337c99bd1f74.zip
logging: Customizable zap cores (#6381)
Diffstat (limited to 'logging.go')
-rw-r--r--logging.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/logging.go b/logging.go
index d3e7bf32b..ca10beeed 100644
--- a/logging.go
+++ b/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
}