TerminalLoggingMiddleware

 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. SQL Log Middleware by joshua 7 years, 1 month ago
  2. SQL Log Middleware w/query count & exec time by tobias 7 years ago
  3. Middelware to remember sql query log from before a redirect by miracle2k 6 years, 7 months ago
  4. SQL Log Middleware - with multiple databases by guglielmocelata 3 years, 2 months ago
  5. SQL Log To Console Middleware by davepeck 4 years, 8 months 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 :)

#

(Forgotten your password?)