Logger console output to stdout or stderr depending on level

Hi,

I was wondering if there is currently a configuration option to have debug/info logs go to stdout and warn/error go to stderr. This would fit well with Docker’s syslog backend.

Is this currently possible with configuration of the console backend, or would I need a custom Logger backend?

Thanks!

4 Likes

https://hexdocs.pm/logger/Logger.html#module-backends

:device - the device to log error messages to. Defaults to :user but can be changed to something else such as :standard_error.

2 Likes

Thank you for pointing the device option. I couldn’t however find a way to configure multiple instances of the console backend, to apply different device and level config options.

1 Like

I ended up using a different approach to get the logs out of the docker container: mapping the host /dev/log and using a syslog backend to write directly to it.

The container is started with -v /dev/log:/dev/log in docker run. The host is running syslog-ng as the log collector.

The application uses a custom Logger backend (https://github.com/pma/logger_syslog_backend) to write directly to the /dev/log Unix Socket.

2 Likes