Amazon Linux rsyslog config override

amazon-amiamazon-web-servicesrsyslog

I am using Amazon Linux AMI release 2015.03, I am trying to configure rsyslog to redirect logs to a remote logging server (in this case, logstash) by dropping a conf file in /etc/rsyslog.d.

The remote logging configuration seems to work fine, but the logs are still written to /var/log/messages as well. Which is a problem because they are filling up the disk.

My conf file looks like this:

# Log docker generated log messages to logstash
:syslogtag, startswith, "docker" @x.x.x.x:5000    
& ~

After some investigation with some other systems, I found that the rsyslog.conf file that exists by default in Amazon Linux is including this directive at the very end of the conf file:

$IncludeConfig /etc/rsyslog.d/*.conf

Other systems I have used have this directive higher up in the config file.. definitely before the default log configs. It appears to me that the defaults cannot be overridden because of this. Am I missing something?

Best Answer

It appears to me that the defaults cannot be overridden because of this. Am I missing something?

Don't think of it as overriding defaults, but you are otherwise correct. In your file, the & ~ is discarding the log message preventing further processing. If this occurs above the built-in processing for /var/log/messages, the log message will be dropped and thus excluded from that file. Since your $IncludeConfig is occurring after, so is your drop statement.

You have two options;

  1. Move the $IncludeConfig statement up.
  2. Fix log rotation so that your disk does not fill.

I would personally prefer the latter because I like to keep logs locally (for a reasonable period of time) as well as forward them to a remote server for aggregation/retention. Having log messages available in /var/log/messages will make troubleshooting more convenient as well as easier for anyone else using the system due to this being the expected location.