Logging from a plugin?

Is there anyway to log from a caddy plugin? I’m working on a authentication plugin and looking to add debug or informational log messages ideally outputted to the configured error log. Specifically to log Conn failures to the external auth server for future troubleshooting purposes.

I thought I could hook into httpserver.Logger but I’m not having any luck

The errors directive will log errors encountered by handling the request. Follow the godoc instructions on the [httpserver.Handler](httpserver package - github.com/mholt/caddy/caddyhttp/httpserver - pkg.go.dev] type for how to report such errors (hint: you return the error values).

Thanks @matt I already got that. Main logic already returns errors. I was thinking to have an optional debug directive, to allow more output what the internals are doing. I’ll code it up to just return err instead I guess.

It might be nice to have the ability to pass a logger to plugins. Just a thought.

I agree, I’ll keep that in mind for the future.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.