rsyslog – create dynamic files

With the following configuration you can automatically let rsyslog create new files every day depending on $msg

Create a new file under /etc/rsyslog.d/ by using nano or vi.
For example:

sudo nano /etc/rsyslog.d/30-test.conf
if then
$template DailyDynFileNGINX,"/var/log/nginx_%$YEAR%-%$MONTH%-%$DAY%"
if ($msg contains "nginx")
then {
     ?DailyDynFileNGINX
}
conventional configuration
$template DailyDynFileNGINX,"/var/log/nginx_%$YEAR%-%$MONTH%-%$DAY%"
:msg,contains,"nginx" ?DailyDynFileNGINX

Restart service

systemctl restart rsyslog