Articles Tagged logging

Debug SQL in django test

Debug SQL in django test

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 ...

Posted on 2015-03-04

Django logging settings

Let's look at default django logging settings and try to make them more useful.

Here what we have in after command 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 for
# more details on how ...

Posted on 2013-09-26

Python logging for every day

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 print instead of logging, because i can't remember all those complicated logging settings. But then, if script is launched often or i must provide it ...

Posted on 2013-08-20