summaryrefslogtreecommitdiff
path: root/modules/logging
diff options
context:
space:
mode:
Diffstat (limited to 'modules/logging')
-rw-r--r--modules/logging/filters.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/logging/filters.go b/modules/logging/filters.go
index a5a917d..a4e3c73 100644
--- a/modules/logging/filters.go
+++ b/modules/logging/filters.go
@@ -25,6 +25,7 @@ import (
func init() {
caddy.RegisterModule(DeleteFilter{})
+ caddy.RegisterModule(ReplaceFilter{})
caddy.RegisterModule(IPMaskFilter{})
}
@@ -57,6 +58,37 @@ func (DeleteFilter) Filter(in zapcore.Field) zapcore.Field {
return in
}
+// ReplaceFilter is a Caddy log field filter that
+// replaces the field with the indicated string.
+type ReplaceFilter struct {
+ Value string `json:"value,omitempty"`
+}
+
+// CaddyModule returns the Caddy module information.
+func (ReplaceFilter) CaddyModule() caddy.ModuleInfo {
+ return caddy.ModuleInfo{
+ ID: "caddy.logging.encoders.filter.replace",
+ New: func() caddy.Module { return new(ReplaceFilter) },
+ }
+}
+
+// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
+func (f *ReplaceFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
+ for d.Next() {
+ if d.NextArg() {
+ f.Value = d.Val()
+ }
+ }
+ return nil
+}
+
+// Filter filters the input field with the replacement value.
+func (f *ReplaceFilter) Filter(in zapcore.Field) zapcore.Field {
+ in.Type = zapcore.StringType
+ in.String = f.Value
+ return in
+}
+
// IPMaskFilter is a Caddy log field filter that
// masks IP addresses.
type IPMaskFilter struct {