You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cron fails to log, while calling the function in django's shell works #31
Yet, when I add the cron job using python manage.py crontab add everything works (I can see the end result appear), yet nothing gets logged. Any reason why logging should work using the shell, but not as a cron?
Shouldn't be there a logger for app.tasks as well? Depending on how log propagation is configured, that may a reason. But sure, if it's working from the django shell...I try to check that soon.
When runnig python manage.py crontab show it returns: Currently active jobs in crontab: d2cbb85ad5f39a8d633df70b63312728 -> ('0/8 * * * *', 'scraper.tasks.my_scheduled_job')
and running python manage.py crontab run d2cbb85ad5f39a8d633df70b63312728 both correctly runs the function, and logs correctly. However, when cron runs the function, I can see the results showing up in the database, but nothing is being logged.
Maybe we're running into a problem because the current working dir differs when started via cron. Please change the FileHandler's filename to be absolute. Does this help?
Another try: switch to ConsoleHandler and pipe result into a file:
Activity
kraiz commentedon Mar 21, 2016
Shouldn't be there a logger for
app.tasksas well? Depending on how log propagation is configured, that may a reason. But sure, if it's working from the django shell...I try to check that soon.kraiz commentedon Mar 29, 2016
Can you provide your Django & Python version with your (simplified) settings for CRONJOBS, LOGGING?
Additionally what happens when you run
and find the logging job's hashed id and run
Does the logging work in this case?
washougal commentedon Mar 29, 2016
Django: 1.9.4, Py: 2.7.11
In settings.py:
When runnig
python manage.py crontab showit returns:Currently active jobs in crontab: d2cbb85ad5f39a8d633df70b63312728 -> ('0/8 * * * *', 'scraper.tasks.my_scheduled_job')and running
python manage.py crontab run d2cbb85ad5f39a8d633df70b63312728both correctly runs the function, and logs correctly. However, when cron runs the function, I can see the results showing up in the database, but nothing is being logged.kraiz commentedon Apr 1, 2016
Maybe we're running into a problem because the current working dir differs when started via cron. Please change the FileHandler's filename to be absolute. Does this help?
Another try: switch to ConsoleHandler and pipe result into a file:
Does this work?
reata commentedon May 6, 2016
I came into the same problem. After changing the FileHandler's filename to be absolute path, it all settled. Probably the working dir issue. Thanks.
added hint about absolute path for logging
kraiz commentedon May 8, 2016
Thanks for sharing @Ryan-ZJU. I added a faq entry about this. Hopefully this helps the next one :)