2

There are answers that suggest changing this:

*.*;auth,authpriv.none           -/var/log/syslog
#cron.*                          -/var/log/cron.log

Into this:

*.*;cron,auth,authpriv.none      -/var/log/syslog
cron.*                           -/var/log/cron.log

This works, but it needs editing first line in rather precise manner, making complications when you want to automate configuration.

Yes, it is doable using sed or Salt file.replace state, but I would like to implement by appending/prepending rsyslog.conf file, or even better - by creating /etc/rsyslog.d/(00|99)-my-cron-log.conf to make it more robust and distribution-agnostic, though I do not follow rsyslog.conf configuration logic enough to make it working. I can't get "CRON" lines removed from syslog.log, except when using example above.

Is it even possible to disable cron to log into syslog.log without modifying package maintainer config lines?

user9517
  • 115,471
  • 20
  • 215
  • 297

2 Answers2

0

As of 2021 at least, creating a conf file in /etc/rsyslog.d/ that is loaded before the default (in Debian derived systems) conf file /etc/rsyslog.d/50-default.conf does work. The name should be anything like (00-49)-name.conf.

For example, I created a file /etc/rsyslog.d/00-custom.conf:

# Don't overflow logs, suppress cron logs for tasks running every minute
# (needs to append "#minutely" as a comment at the end of such commands)
if $programname == 'CRON' and $msg contains '#minutely' then stop

# Put info level cron logs in a separated file.
cron.=info      /var/log/cron.log  # redirect if level is exactly 'info'
cron.notice     -/var/log/syslog   # keep sending to syslog if level is 'notice' or higher
cron.*          stop               # drop messages here to avoid default redirections

For changes to take effect immediately:

# systemctl restart rsyslog.service
leogama
  • 101
  • 1
0

Is it even possible to disable cron to log into syslog.log without modifying package maintainer config lines?

No. The cron(8) from Debian based systems does provide a -L option that sets The log level a value of 0 disables logging but thg same is not available in EL based distros.

There is no real reason not to edit the files. I would probably just create a standard file and have my CM solution deploy it.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • I do not want to disable cron logging completely, only from syslog.log (log to cron.log instead). Could I create "standard file" to be placed to /etc/rsyslog.d/(00|99)-cron.log? I just would prefer avoiding merging config files on system upgrade, for example. – Vincas Dargis Dec 14 '15 at 11:25