How to Configure a Custom Log File and Location For Rsyslog (instead of /var/log/messages) on CentOS/RHEL

In some situations or environments, there may be a requirement to configure the rsyslog service to log to a different log file or location than to the default /var/log/messages. This article describes how rsyslog can be configured to do this.

This can be done by putting the path and log name that needs to used instead of /var/log/messages in the /etc/rsyslog.conf file. The following is an example of how to do this using /test as the log path, and test.log as the log file name.

1. Create the directory where the new log file will be created:

# mkdir /test

This can also be a preexisting location.

2. Edit the rsyslog configuration file /etc/rsyslog.conf, replace the “/var/log/messages” by the new directory and log file name:

# vi /etc/rsyslog.conf

Before:

*.info;mail.none;authpriv.none;cron.none /var/log/messages

After:

*.info;mail.none;authpriv.none;cron.none /test/test.log

3. Restart the rsyslog service for the changes to take effect.

For CentOS/RHEL 6, do:

# service rsyslog restart

For CentOS/RHEL 7, do:

# systemctl restart rsyslog