Articles Tagged logging
In django tests we can measure number of sql queries:
def test_home(self): with self.assertNumQueries(1): response = self.client.get('/') self.assertEqual(response.status_code, 200)
If code in context of
assertNumQueries will make other number of DB attempts than expected (here 1), test will throw error. But when test fails it is sometimes hard to understand, what unexpected query was made. To debug such case very useful to log SQL expressions to console. Below ...
Let's look at default django logging settings and try to make them more useful.
Here what we have in settings.py after command
django-admin.py startproject project_name (django 1.5):
# A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how ...
When writing a small python program or script, it is sometimes needed to output debug message or maybe event. It is known, that python has logging module exactly for that purpose. But in my case usually such thing happens: it is lack of time and hands just writes