0

I have a Docker image for cron tasks. Here is the Dockerfile:

FROM php:8.0-fpm

RUN apt-get update
RUN apt-get install -y cron rsyslog

RUN touch /var/log/cron.log
RUN chmod 0777 /var/log/cron.log

COPY ./app /var/www/app
COPY crontab /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab

COPY 02-cron.conf /etc/rsyslog.d/02-cron.conf

CMD service rsyslog start && service cron start && tail -f /dev/null

By default rsyslog logs cron to /var/log/syslog. I want to log cron to a separate file /var/log/cron.log.

rsyslog's master config /etc/rsyslog.conf has the following lines:

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

I want to disable logging cron to /var/log/syslog and enable logging it to /var/log/cron.log by adding one more config /etc/rsyslog.d/02-cron.conf:

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

But the result is that cron logs to both /var/log/syslog and /var/log/cron.log.

1 Answer 1

1

Line in you config:

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

make it like this:

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

to stop cron from logging in syslog

And also you can add dash (-) in front of the path for cron log to avoid flush of buffers on every write. So your cron line to become:

cron.*                          -/var/log/cron.log
3
  • I've done everything as you suggested but logs are still written in two files. Commented Aug 10, 2021 at 7:13
  • @femalemoustache, have you restart rsyslog after you change the config? Commented Aug 10, 2021 at 7:24
  • yes, I stop and remove container and image before each change. Commented Aug 10, 2021 at 12:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.