Django: show/log ORM sql calls from python shell
Question: Using the excellent [Django-Devserver](http://github.com/dcramer/django-
devserver) I'm finding all kinds of interesting and unexpected SQL calls in my
code. I wanted to find where the calls are coming from, and so I'm looking for
a way to get a log or print-out of all SQL calls generated by the Django ORM
in the Python shell. That is, when I do a Django ORM call via the Python
shell, I'd like to see the resulting SQL printed out or logged.

I noticed several solutions that add log info to the html page. Is there an
easy way to dump to the command line instead?


Answer: If you're using Django 1.3:

    
    
    import logging
    l = logging.getLogger('django.db.backends')
    l.setLevel(logging.DEBUG)
    l.addHandler(logging.StreamHandler())
    

