How can I make hoptoad in Django 1.2 log errors to log file as well as send airbrake notifications? - django

We're using django 1.2.7 and the hoptoad logging middleware (hoptoad.middleware.HoptoadNotifierMiddleware).
When an error occurs, the error message gets sent to airbrake, but it does not seem to get logged to the django log file. It seems like it's intercepted by hoptoad exclusively.
Does anyone know how to also get the errors logged to the local django log file on disk? I couldn't find any such option in the hoptoad documentation.
Is there a custom modification needed to the hoptoad middleware class?

Related

django send_mail has insecure link to http://dpaste.com/

I am trying to send emails with django and for that I use send_email from django.core.mail, but it has a link to http://dpaste.com/, with HTTP and my website is in HTTPS.
This is the message I get in my console:
Mixed Content: The page at 'https://b...' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://dpaste.com/'. This endpoint should be made available over a secure connection.
It means that the standard send_mail from django blocks my secure connection? How can that be possible? What othe solutions do I have to send email with django?
Thanks
The problem was happening because I had DEBUG: TRUE and there was an error in the code. Therefor, django was using dpaste to throw the error.
The solution was to turn the DEBUG off or fix the error in the code.
Thanks, Suresh, for helping me on that.

django error reporting request url - how to use this locally?

I have a django project which used the normal email admins on an unhandled exception when debug is set to False. ie in production.
I normally just review the error message and the stack trace. However I clicked on the request url link, which managed to recreate the error on the prouduction site (which then fired off another email).
What is this request url? Does it recreate the full http request (including the session etc..) which resulted in the original error?
Can I get the link to point to a local version of the site? (As after fixing a previous error clicking on the earlier request url has manged to create a recent error that we have been unable to reproduce, so it would be good to recreate this locally so it can be debugged.

Save django request logs in a file

Django shows the requests logs in command line, I want to save that logs in a file. I found a solution here but it saves the logs only that we print manually. Can we save all of the request and response logs in a separate file?
To log the Django request debug events, check out my answer here about using the fail-nicely-django config. You will also get 4xx and 5xx request events logged from Django's default loggers.
Note, though, that 2xx requests generally don't get logged by Django, if that's what you are after (only runserver shows them in the console). There is a workaround mentioned here, but you should generally use your server's access logs for these in production (e.g. access.log in nginx/Apache).
This should work on both linux and windows I hope:
python manage.py runserver > logs.txt

Missing logs in django

I have a django app on Webfaction, and it seems that logs it is sending do not get written in the log file.
I have the following code:
log.debug('batch, guid: %s' % request.POST['guid'])
events = request.POST.getlist('logbatch[]')
for event in events:
a = event.split(';')
userlog = UserLog(csq_id=CsqId.objects.get(guid=request.POST['guid']), elementId=a[1], event=a[0], counter=int(a[2]), clientTime=js_time_to_python(int(a[3])))
userlog.save()
In general, logging works and is configured correctly. However, when I look in the database, I can see UserLog objects that are not logged in. As the DB insertion happens after the logging, I am certain that django did log the code. So why is it not in the log file?
Read the Django documentation on logging. You need to configure logging in your settings.py first, before you start using it. There is also an example configuration provided in the documentation.

Catching Django Errors When Client Is Not A Web Browser?

I'm building a Django web service that is called from an application. When it throws an exception, I can't see the Django debug page, and can't get to it because the calling application doesn't behave like a web browser (and I don't have control over that application).
Is there a way to redirect the Django error page to a a log file rather than to the calling client, possibly via changing the FastCGI config (I'm using lighty + FastCGI)? Or maybe a "dump to file" config option or some sort of LogExceptionToFile() method within the framework itself?
You might try just creating custom ExceptionMiddleware. Just change the process_exception method to log the exception and request data somewhere.
Here's an example: http://www.peterbe.com/plog/who-was-logged-in-during-a-django-exception
If the exception in the django app is not caught, and DEBUG = True, then the exception should be sent to the client.
Some options to help you get debugging info:
Enable and configure logging
Set up email error reporting
Use something like Wireshark to inspect the HTTP request and responses.