Login

TerminalLoggingMiddleware

Author:
heckj
Posted:
June 4, 2007
Language:
Python
Version:
.96
Score:
7 (after 7 ratings)

A handy ANSI-colored logging mechanism to display the SQL queries and times in the terminal when using django-admin.py runserver. DEBUG mode must be true for this to work.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from django.db import connection 

class TerminalLogging:
    def process_response(self, request, response):
        from sys import stdout
        if stdout.isatty():
            for query in connection.queries :
                print "\033[1;31m[%s]\033[0m \033[1m%s\033[0m" % (query['time'],
 " ".join(query['sql'].split()))
        return response

More like this

  1. Django Settings Assignment Expressions aka Walrus Operator example by webology 2 weeks, 5 days ago
  2. codigo alto nivel by MrRocklion 2 months, 2 weeks ago
  3. Load template from specific app by Krzysiek555 3 months ago
  4. PostgreSQL JSON subqueries by dolamroth 3 months, 1 week ago
  5. "Magic Link" Management Command by webology 8 months, 1 week ago

Comments

akhavr (on June 4, 2007):

Where the connection object on the 5th line comes from?

#

udfalkso (on June 4, 2007):

from django.db import connection

#

akhavr (on June 5, 2007):

I guess it would be helpful to include that line

from django.db import connection

to the snippet itself :)

#

Please login first before commenting.