I am using rsyslogd and I want to put messages into custom log files based on their content (using a template) as well as use a custom file format (using a template). The rsyslog documentation provides good information on how to create a template and apply it based on the contents/facility/etc. of a message, but does not show how to use apply multiple templates to a single message.
After much searching, I found an example on this stack overflow answer of using multiple templates on a single message, but since that question was on a different topic, I thought this was worth its own question.
The solution is as easy as the example below (copied from the answer linked above):
$template MsgFormat,"%msg%\n"
$template ApacheRemoteCustom,"/var/log/manager/access.log"
if $syslogfacility-text == 'local6' and $programname == 'apache' then -?ApacheRemoteCustom;MsgFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With