-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set the default logger programatically? #5938
Comments
What do you mean, exactly? Couldn't we fix that instead? What are your needs? This is sounding kinda like an XY Problem. |
I'd be interested to know what about the encoder we could fix or improve to meet your needs. What are your requirements? |
As for the XY Problem, I thought I already stated the problem - I'm using Caddy as an embedded component in a service and already have a configured zap logger by the time I initialise Caddy. Otherwise, I would need to ensure that the logger configuration from the service configuration is kept in sync with the caddy config file. Therefore, I was looking for a solution on how to also use that logger for Caddy. As to what I'm missing:
I would really like to find a solution to this as I'm now having two different logging formats interspersed in the logs which complicates processing. Not a real show stopper, just an eye sore :) Otherwise, I'm a very happy user! |
You can set caddy/modules/logging/encoders.go Lines 223 to 260 in 7e52db8
We can add an option to enable |
See #5944, I think this'll do what you need? |
Thanks, that will allow me to solve my problem by duplicating logging information. I understand that the majority of folks are using Caddy as a "closed" application, configured by Caddy's own config file. And maybe, I'm the only one using it differently, but it can be used differently and having extension points, like providing one own's logger would make it even more useful. In any case, thanks for the help. |
I'm using Caddy as an embedded component in a service and would like to be able to set at least the default logger to the
zap logger the service has already configured by the time Caddy is started.
The primary reason for that is that setting up the logger in Caddy's config file is missing certain capabilities (primarily related to the encoder). But from management point of view, I want to avoid having to spread/duplicate logger configuration across multiple places (my service & Caddy config).
I guess the easiest place is to "extend" the
Log
function inlogging.go
. Being able to set thedefaultLogger
variable is most likely not going to work as it seems to be "recreated" insetupNewDefault
based on itsCustomLog
settings - which lack what I need.Or is there already a way to achieve that without any further code changes?
The text was updated successfully, but these errors were encountered: