summaryrefslogtreecommitdiff
path: root/modules/logging
diff options
context:
space:
mode:
Diffstat (limited to 'modules/logging')
-rw-r--r--modules/logging/filterencoder.go30
1 files changed, 8 insertions, 22 deletions
diff --git a/modules/logging/filterencoder.go b/modules/logging/filterencoder.go
index d1c335f..cdb552d 100644
--- a/modules/logging/filterencoder.go
+++ b/modules/logging/filterencoder.go
@@ -115,21 +115,14 @@ func (fe *FilterEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr()
}
moduleName := d.Val()
- mod, err := caddy.GetModule("caddy.logging.encoders." + moduleName)
- if err != nil {
- return d.Errf("getting log encoder module named '%s': %v", moduleName, err)
- }
- unm, ok := mod.New().(caddyfile.Unmarshaler)
- if !ok {
- return d.Errf("log encoder module '%s' is not a Caddyfile unmarshaler", mod)
- }
- err = unm.UnmarshalCaddyfile(d.NewFromNextSegment())
+ moduleID := "caddy.logging.encoders." + moduleName
+ unm, err := caddyfile.UnmarshalModule(d, moduleID)
if err != nil {
return err
}
enc, ok := unm.(zapcore.Encoder)
if !ok {
- return d.Errf("module %s is not a zapcore.Encoder", mod)
+ return d.Errf("module %s (%T) is not a zapcore.Encoder", moduleID, unm)
}
fe.WrappedRaw = caddyconfig.JSONModuleObject(enc, "format", moduleName, nil)
@@ -140,26 +133,19 @@ func (fe *FilterEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr()
}
filterName := d.Val()
- mod, err := caddy.GetModule("caddy.logging.encoders.filter." + filterName)
- if err != nil {
- return d.Errf("getting log filter module named '%s': %v", filterName, err)
- }
- unm, ok := mod.New().(caddyfile.Unmarshaler)
- if !ok {
- return d.Errf("log encoder module '%s' is not a Caddyfile unmarshaler", mod)
- }
- err = unm.UnmarshalCaddyfile(d.NewFromNextSegment())
+ moduleID := "caddy.logging.encoders.filter." + filterName
+ unm, err := caddyfile.UnmarshalModule(d, moduleID)
if err != nil {
return err
}
- f, ok := unm.(LogFieldFilter)
+ filter, ok := unm.(LogFieldFilter)
if !ok {
- return d.Errf("module %s is not a LogFieldFilter", mod)
+ return d.Errf("module %s (%T) is not a logging.LogFieldFilter", moduleID, unm)
}
if fe.FieldsRaw == nil {
fe.FieldsRaw = make(map[string]json.RawMessage)
}
- fe.FieldsRaw[field] = caddyconfig.JSONModuleObject(f, "filter", filterName, nil)
+ fe.FieldsRaw[field] = caddyconfig.JSONModuleObject(filter, "filter", filterName, nil)
}
default: