@@ -13,16 +13,16 @@ def __init__(self):
13
13
if threading is None :
14
14
raise NotImplementedError ("threading module is not available, \
15
15
the logging panel cannot be used without it" )
16
- self .records = {} # a dictionary that maps threads to log records
17
-
16
+ self .records = {} # a dictionary that maps threads to log records
17
+
18
18
def add_record (self , record , thread = None ):
19
19
# Avoid logging SQL queries since they are already in the SQL panel
20
20
# TODO: Make this check whether SQL panel is enabled
21
21
if record .get ('channel' , '' ) == 'django.db.backends' :
22
22
return
23
-
23
+
24
24
self .get_records (thread ).append (record )
25
-
25
+
26
26
def get_records (self , thread = None ):
27
27
"""
28
28
Returns a list of records for the provided thread, of if none is provided,
@@ -33,7 +33,7 @@ def get_records(self, thread=None):
33
33
if thread not in self .records :
34
34
self .records [thread ] = []
35
35
return self .records [thread ]
36
-
36
+
37
37
def clear_records (self , thread = None ):
38
38
if thread is None :
39
39
thread = threading .currentThread ()
@@ -45,7 +45,7 @@ class ThreadTrackingHandler(logging.Handler):
45
45
def __init__ (self , collector ):
46
46
logging .Handler .__init__ (self )
47
47
self .collector = collector
48
-
48
+
49
49
def emit (self , record ):
50
50
record = {
51
51
'message' : record .getMessage (),
@@ -75,7 +75,7 @@ class LogbookThreadTrackingHandler(logbook.handlers.Handler):
75
75
def __init__ (self , collector ):
76
76
logbook .handlers .Handler .__init__ (self , bubble = True )
77
77
self .collector = collector
78
-
78
+
79
79
def emit (self , record ):
80
80
record = {
81
81
'message' : record .message ,
@@ -86,37 +86,37 @@ def emit(self, record):
86
86
'channel' : record .channel ,
87
87
}
88
88
self .collector .add_record (record )
89
-
90
-
89
+
91
90
logbook_handler = LogbookThreadTrackingHandler (collector )
92
- logbook_handler .push_application () # register with logbook
91
+ logbook_handler .push_application () # register with logbook
92
+
93
93
94
94
class LoggingPanel (DebugPanel ):
95
95
name = 'Logging'
96
96
template = 'debug_toolbar/panels/logger.html'
97
97
has_content = True
98
-
98
+
99
99
def process_request (self , request ):
100
100
collector .clear_records ()
101
-
101
+
102
102
def process_response (self , request , response ):
103
103
records = self .get_and_delete ()
104
104
self .record_stats ({'records' : records })
105
-
105
+
106
106
def get_and_delete (self ):
107
107
records = collector .get_records ()
108
108
collector .clear_records ()
109
109
return records
110
-
110
+
111
111
def nav_title (self ):
112
112
return _ ("Logging" )
113
-
113
+
114
114
def nav_subtitle (self ):
115
115
# FIXME l10n: use ngettext
116
116
return "%s message%s" % (len (collector .get_records ()), (len (collector .get_records ()) == 1 ) and '' or 's' )
117
-
117
+
118
118
def title (self ):
119
119
return _ ('Log Messages' )
120
-
120
+
121
121
def url (self ):
122
122
return ''
0 commit comments