Rsyslog – Change Timestamp Format for Specific Filter

linuxloggingrsyslog

I wish to change my rsyslog timestamp format to RFC-3339 of specific log file (msg).

I have the following file /etc/rsyslog.d/10-zn.conf
with the following content:

:msg, contains, "my_prefix"       /var/log/zn.log

which means that save to /var/log/zn.log all of the lines which contains "my_prefix".

I wish to change the timestamp from RSYSLOG_TraditionalFileFormat which is %b %d %H:%M:%S
to RFC-3339 but I can find out how to do it just for the logs which contains my prefix, is there any way to do it?

thank you

Best Answer

Found the right configuration

if $msg contains '{{my_prefix}}' then { 
        action(type="omfile" file="/var/log/zn.log" template="RSYSLOG_FileFormat")
}

RSYSLOG_FileFormat template already come with RFC3339 timestamp