mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
logging: Implement rename filter, changes field key names (#4745)
This commit is contained in:
parent
3017b245c9
commit
0be3d99543
1 changed files with 37 additions and 1 deletions
|
@ -31,12 +31,13 @@ import (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy.RegisterModule(DeleteFilter{})
|
caddy.RegisterModule(DeleteFilter{})
|
||||||
|
caddy.RegisterModule(HashFilter{})
|
||||||
caddy.RegisterModule(ReplaceFilter{})
|
caddy.RegisterModule(ReplaceFilter{})
|
||||||
caddy.RegisterModule(IPMaskFilter{})
|
caddy.RegisterModule(IPMaskFilter{})
|
||||||
caddy.RegisterModule(QueryFilter{})
|
caddy.RegisterModule(QueryFilter{})
|
||||||
caddy.RegisterModule(CookieFilter{})
|
caddy.RegisterModule(CookieFilter{})
|
||||||
caddy.RegisterModule(RegexpFilter{})
|
caddy.RegisterModule(RegexpFilter{})
|
||||||
caddy.RegisterModule(HashFilter{})
|
caddy.RegisterModule(RenameFilter{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogFieldFilter can filter (or manipulate)
|
// LogFieldFilter can filter (or manipulate)
|
||||||
|
@ -542,21 +543,56 @@ func (f *RegexpFilter) Filter(in zapcore.Field) zapcore.Field {
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenameFilter is a Caddy log field filter that
|
||||||
|
// renames the field's key with the indicated name.
|
||||||
|
type RenameFilter struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CaddyModule returns the Caddy module information.
|
||||||
|
func (RenameFilter) CaddyModule() caddy.ModuleInfo {
|
||||||
|
return caddy.ModuleInfo{
|
||||||
|
ID: "caddy.logging.encoders.filter.rename",
|
||||||
|
New: func() caddy.Module { return new(RenameFilter) },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalCaddyfile sets up the module from Caddyfile tokens.
|
||||||
|
func (f *RenameFilter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
|
for d.Next() {
|
||||||
|
if d.NextArg() {
|
||||||
|
f.Name = d.Val()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter renames the input field with the replacement name.
|
||||||
|
func (f *RenameFilter) Filter(in zapcore.Field) zapcore.Field {
|
||||||
|
in.Type = zapcore.StringType
|
||||||
|
in.Key = f.Name
|
||||||
|
return in
|
||||||
|
}
|
||||||
|
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ LogFieldFilter = (*DeleteFilter)(nil)
|
_ LogFieldFilter = (*DeleteFilter)(nil)
|
||||||
|
_ LogFieldFilter = (*HashFilter)(nil)
|
||||||
_ LogFieldFilter = (*ReplaceFilter)(nil)
|
_ LogFieldFilter = (*ReplaceFilter)(nil)
|
||||||
_ LogFieldFilter = (*IPMaskFilter)(nil)
|
_ LogFieldFilter = (*IPMaskFilter)(nil)
|
||||||
_ LogFieldFilter = (*QueryFilter)(nil)
|
_ LogFieldFilter = (*QueryFilter)(nil)
|
||||||
_ LogFieldFilter = (*CookieFilter)(nil)
|
_ LogFieldFilter = (*CookieFilter)(nil)
|
||||||
_ LogFieldFilter = (*RegexpFilter)(nil)
|
_ LogFieldFilter = (*RegexpFilter)(nil)
|
||||||
|
_ LogFieldFilter = (*RenameFilter)(nil)
|
||||||
|
|
||||||
_ caddyfile.Unmarshaler = (*DeleteFilter)(nil)
|
_ caddyfile.Unmarshaler = (*DeleteFilter)(nil)
|
||||||
|
_ caddyfile.Unmarshaler = (*HashFilter)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*ReplaceFilter)(nil)
|
_ caddyfile.Unmarshaler = (*ReplaceFilter)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*IPMaskFilter)(nil)
|
_ caddyfile.Unmarshaler = (*IPMaskFilter)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*QueryFilter)(nil)
|
_ caddyfile.Unmarshaler = (*QueryFilter)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*CookieFilter)(nil)
|
_ caddyfile.Unmarshaler = (*CookieFilter)(nil)
|
||||||
_ caddyfile.Unmarshaler = (*RegexpFilter)(nil)
|
_ caddyfile.Unmarshaler = (*RegexpFilter)(nil)
|
||||||
|
_ caddyfile.Unmarshaler = (*RenameFilter)(nil)
|
||||||
|
|
||||||
_ caddy.Provisioner = (*IPMaskFilter)(nil)
|
_ caddy.Provisioner = (*IPMaskFilter)(nil)
|
||||||
_ caddy.Provisioner = (*RegexpFilter)(nil)
|
_ caddy.Provisioner = (*RegexpFilter)(nil)
|
||||||
|
|
Loading…
Reference in a new issue