Category index for “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 is description how to do it.

    Comments Read More
  • Django logging settings

    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):

    Comments Read More
  • 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 to customer, i have to replace all prints with logging, because it is better to log all messages to file. So, not to keep in my head all these settings, i am writing this post.

    Comments Read More