In settings.py I have setup a way to log my messages like this:
logging.basicConfig(
level = logging.DEBUG,
format = '%(asctime)s %(levelname)s %(message)s',
filename = 'log/sdout.log',
filemode = 'a'
)
However sometimes django fails silently. Like in the case of signals. My problem is that at my work pc everything works great. At my production server something is wrong. I know the place of the exception. I just can’t see why it fails.
So I placed something like this:
logging.debug('before error') #this is printed out
try:
end_date = start_date.date() + relativedelta(months = +month_diff)
next_billing_date = start_date.date() + datetime.timedelta(7)
except :
import sys, traceback
traceback.print_exc(file=sys.stdout)
logging.debug('after error') #I never get to that part.
EDIT: The above snippet lies in my models.py called when I receive a POST from paypal
After failure I try to look into my apache error logs and my logging file but see no errors, whatsoever.
How can I see what is wrong with this code?
I would first recommended sentry – if you can’t install it due to system restrictions – it is now available as a hosted service at getsentry.com and like most such services, there is a free tier.
However, the issue could be that WSGI by default blocks writing to
stdout, as detailed in the documentation wiki under application issues.There are few workarounds posted at that page, but the one I would start with is to add the following to your WSGI configuration:
WSGIRestrictStdout OffSee if that helps with error logging.