-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
This issue is to collect and gauge interest in this feature before we spend time working on it.
There's demand for having Caddy skip logging access logs selectively; I opened issue #4689 which should solve the specific case of access logs. Caddy doesn't only emit access logs, though. There's all kinds of logs, from many different sources (other Caddy apps, stdlib captured logs, dependencies).
The idea is that we could implement a system for configuring "matchers" for individual log messages based on the contents of the zap log entry. This could be hooked in implementing a custom zapcore.Core to decide whether to write the log.
We actually already do implement a custom Core to override Check() to implement an include/exclude list by logger name:
Lines 550 to 557 in afca242
| // Check only allows the log entry if its logger name | |
| // is allowed from the include/exclude rules of fc.cl. | |
| func (fc *filteringCore) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry { | |
| if fc.cl.loggerAllowed(e.LoggerName, false) { | |
| return fc.Core.Check(e, ce) | |
| } | |
| return ce | |
| } |
This is a good start and may usually be enough for most users to hide certain logs, but it's possible that sometimes only specific patterns of logs from a particular logger should be hidden, not the entire logger.
My idea is that we add support for pluggable log matcher modules which take in the zapcore.Entry and []zapcore.Field and can inspect its contents to decide whether we want to log it. It would go in the config in here https://caddyserver.com/docs/json/logging/logs/ (i.e. just under include and exclude). Not sure what we'd call it, maybe checkers? It would be an array of modules that implement an interface like:
interface LogEntryChecker {
ShouldSkip(zapcore.Entry, []zapcore.Field) bool
}We'd have to run this checking logic in Write(Entry, []Field) error since that's the only place we have access to both the entry and the fields. This was suggested as a solution in uber-go/zap#1021 (comment) as an answer to a similar question.
We could provide simple built-in matchers like an exact value match of a particular field by path, like request>method (similar to filter encoders, a not matcher which wraps other matchers to invert the boolean result, etc.
So all that said, this is not an insignificant amount of work, so we'd like to hear what problems this could solve for users. Feedback is welcome on this idea!