Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use more than one template with rsyslog

Tags:

rsyslog

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.

like image 952
Stuart Avatar asked Mar 10 '15 17:03

Stuart


1 Answers

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
like image 178
Stuart Avatar answered Oct 01 '22 08:10

Stuart