How to enable log rotation in rsyslog configuration. The method described in the official documentation of rsyslog using output channels is not working for me.
The script given in the official documentation of rsyslog for output channel is available here: https://www.rsyslog.com/doc/master/tutorials/log_rotation_fix_size.html
module(load="imudp" TimeRequery="500")
module(load="omstdout")
module(load="omelasticsearch")
module(load="mmjsonparse")
module(load="mmutf8fix")
ruleset(name="prismaudit_rs") {
action(type="omfile" dirCreateMode="0777" fileCreateMode="0777" file="/logs/prismaudit.log")
}
$outchannel log_rotation,/logs/prismaudit.log, 3000,/etc/log_rotation_script
*.* :omfile:$log_rotation
#input(type="imptcp" port="514")
input(type="imudp" port="514" ruleset="prismaudit_rs")
This is the snippet of code I am using. I have also tried adding the outputchannel part of code inside the ruleset(after action statement).
My log rotation script: mv -f /logs/prismaudit.log /logs/log_rotation.log.1
First of all, I think you misunderstood something there and should read the documentation again.
The log rotation is not working because the content you currently have in
/etc/log_rotation_script
should be in/etc/rsyslog.conf
or/etc/rsydlog.d/filename.conf
, as the configuration of rsyslog is handled in there.The only purpose of the
/etc/log_rotation_script
is to move a "full" (when the limit of currently 3KB is hit) file to another file/location.The
/etc/rsyslog.conf
(simplified) would then look something like the following:The script which is executed when the max file size is reached, could then just move the file:
/path/to/log_rotation_script