caddyserver / cache-handler

Distributed HTTP caching module for Caddy
Apache License 2.0
262 stars 19 forks source link

Debug logging but without body content #72

Closed rhullah closed 6 months ago

rhullah commented 7 months ago

While configuring caching, I like to see in the logs when a response is pulled from upstream, cached, and served from cache. I've been able to see this by configuring debug logging. But when I configure debug logging, it also logs the response body that was cached. For my API reverse proxied content, that can be handy (though I don't need it). But for my file asset reverse proxied content, it spams the logs with binary data.

Is there a way to configure logging to not include the body content? Or even more granular control of what logs body content (API requests) and what doesn't (file asset downloads)?

darkweak commented 6 months ago

Hello @rhullah, that's not possible. But I could totally remove the body from the logs for everyone. WDYT?

francislavoie commented 6 months ago

IMO usually content length number is enough to signal "yep it's about the same as I expect". Could add a flag to also emit the body in a separate log entry or something. Possibly with a different logger name so it can be written out to a separate file.

darkweak commented 6 months ago

@francislavoie how do you do that?

francislavoie commented 6 months ago

If you mean re logger name, with zap you can do .Named('foo') on a logger which appends a .foo to the logger name, essentially "namespacing" the logger. That way you can separate logs contextually from eachother. In Caddy you can configure loggers to include/exclude by logger name.

rhullah commented 6 months ago

But I could totally remove the body from the logs for everyone.

IMO usually content length number is enough...

I'm my use-case I don't need the body and I don't think debug logging is something that should be regularly configured. But I don't want to speak to other's possible use-cases. If you want to get rid of it, Content-Length is a good alternative.

If you mean re logger name, with zap you can do .Named('foo') on a logger which appends a .foo to the logger name, essentially "namespacing" the logger. That way you can separate logs contextually from eachother. In Caddy you can configure loggers to include/exclude by logger name.

If this is doable I think it's a good solution as it puts the control into user choice and configuration.