0

I use cron to control a python script

*/10 * * * * /usr/bin/python3 /home/user/FillDatabase.py

and its works well so fare. The python script itself produce logging in case of error.

import logging
...
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
...
try:
    ...

except Exception as e:
    logging.info('error while writing: {0} \n'.format(e))

I want so see these python logging messages in the syslog.

i tried

*/10 * * * * /usr/bin/python3 /home/user/FillDatabase.py 2>&1
  • 2
    Does this answer your question? [How to configure logging to syslog in Python?](https://stackoverflow.com/questions/3968669/how-to-configure-logging-to-syslog-in-python) – Sören Nov 05 '22 at 22:01
  • I think no. the logging itself (from the python script to syslog) works, but not "behind" cron. –  Nov 05 '22 at 23:00

1 Answers1

0

found:

Wirte to cron with

sudo crontab -u root -e

give cron the permission to write into syslog

*/10 * * * * /usr/bin/python3 /home/user/FillDatabase.py >> /var/log/syslog 2>&1