I have a syslog-ng container that collects logs from other containers running on the same application, and normal logging works as intended: every container send its logs and syslog-ng saves them on separate files, as defined in syslog-ng.conf.
I'm also trying to save error logs on a different file. I was assuming that everything thrown to STDERR from inside another container should be seen by syslog-ng as an error, so when I started a container like this:
docker run -dit --log-driver syslog --log-opt syslog-address=tcp://my_syslog:601 alpine echo "boom" > /dev/stderr
then I expected syslog-ng to understand it to be an error, but it does not.
This is an extract of my syslog-ng.conf inside the syslog-ng container:
@version: 3.25
source s_net {
network(transport(tcp) port(601));
network(transport(udp) port(514));
};
destination d_error_file {
file("/tmp/errors");
};
filter f_errors {
level(err .. emerg);
};
log {
source(s_net);
filter(f_errors);
destination(d_error_file);
};
How can I tell syslog-ng to treat STDERR messages as errors?
My original reply to set up a
/dev/stderrsource was misinformed. I thought thatsyslog-ngwas running in the host.As
syslog-ngis running in the container, the docker daemon is collecting the logs from the running container and sending it over the network to the syslog server.This is why the filtering has to be performed on the network source which is just as you have done.
I setup the following project to demonstrate an example.
docker-compose.yml
hack.sh: A shell script that logs to stderr and stdout
./data/syslog-ng/conf/syslog-ng.conf: filter
infoto/var/log/sysloganderrorto/var/log/errorOther than creating a different filter for non-error messages, there is little difference between the above
syslog-ngconfiguration and the one you have provided.