Python script logs not printing with supercronic


#1

Hi I have a python script which runs with supercronic. I setup logging to print to stdout like this:

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger("logger")

If I run the script manually I get all output printed to the terminal, but when the cron job runs, all I get is:

2017-09-19T16:45:00.000Z [nex-cron-scripts-dev-cron 02d9182d5b9c]: time="2017-09-19T16:45:00Z" level=info msg=starting iteration=0 job.command="python /usr/src/app/notifications/reminder_notification.py "America/Denver" >/tmp/stdout.log 2>/usr/src/app/notifications/reminder.log" job.position=4 job.schedule="45 16 * * *" 
2017-09-19T16:45:01.685Z [nex-cron-scripts-dev-cron 02d9182d5b9c]: time="2017-09-19T16:45:01Z" level=info msg="job succeeded" iteration=0 job.command="python /usr/src/app/notifications/reminder_notification.py "America/Denver" >/tmp/stdout.log 2>/usr/src/app/notifications/reminder.log" job.position=4 job.schedule="45 16 * * *" 
2017-09-19T16:45:01.685Z [nex-cron-scripts-dev-cron 02d9182d5b9c]: time="2017-09-19T16:45:01Z" level=debug msg="job will run next at 2017-09-20 16:45:00 +0000 UTC" job.command="python /usr/src/app/notifications/reminder_notification.py "America/Denver" >/tmp/stdout.log 2>/usr/src/app/notifications/reminder.log" job.position=4 job.schedule="45 16 * * *"

This is how I start the cron job in Procfile:

cron: while true; do exec supercronic -debug /usr/src/app/crontab; sleep 1; done

I want to be able to see the output of the script when I run aptible logs command for this app.
What am I missing?


#2

It looks like your crontab is set up to write logs to a file:

python /usr/src/app/notifications/reminder_notification.py "America/Denver" >/tmp/stdout.log 2>/usr/src/app/notifications/reminder.log

Removing >/tmp/stdout.log 2>/usr/src/app/notifications/reminder.log from the crontab should do the trick.