How to change timestamp format on rsyslog

mr antoni picture mr antoni · Mar 23, 2018 · Viewed 10.5k times · Source

I want to change the default timestamp format on rsyslog. Currently I am running on RHEL7.2. Syslog version 7.4.7. Now the default format is the following:

Mar 23 09:35:30 localhost DEB  [9125:<console>.<module>:2] debug info

Inside rsyslog.conf I have define the following template:

$template Mytemplate,"%timegenerated% %HOSTNAME% %syslogseverity-text:0:3:uppercase% %msg%\n"

How can I change the format to this YYYY-MM-dd H:i:s ?

Answer

mr antoni picture mr antoni · Mar 23, 2018

The modification is the following:

$template Mytemplate,"%$year%-%$month%-%$day% %timegenerated:12:19:date-rfc3339% %HOSTNAME% %syslogseverity-text:0:3:uppercase% %msg%\n"