File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -509,3 +509,20 @@ def _range_to_str(x, y):
509509 return str (x )
510510 else :
511511 return "{}-{}" .format (x , y )
512+
513+
514+ def check_log_level (logger , loglevel ):
515+ """
516+ Check that the level of the logger is equal to or below loglevel
517+
518+ Use before possibly expensive logging operations, like calling logging in
519+ a loop or building an expensive object that will be logged and thrown away.
520+
521+ Avoid this classic mistake:
522+
523+ logger.info("%s", expensive_function())
524+ """
525+ level = logger .getEffectiveLevel ()
526+ if level <= loglevel :
527+ return True
528+ return False
Original file line number Diff line number Diff line change 1919import logging
2020from os .path import join
2121
22+ from django .conf import settings
23+
2224from nav .auditlog .models import LogEntry
2325from nav .config import NAVConfigParser
2426from nav .models .profiles import Account
27+ from nav .util import check_log_level
2528from nav .web .auth .utils import ACCOUNT_ID_VAR
2629
2730try :
@@ -179,6 +182,10 @@ def get_username(request):
179182 if not request :
180183 return None
181184
185+ if settings .DEBUG or check_log_level (_logger , logging .DEBUG ):
186+ for metakey , value in request .META .items ():
187+ if metakey [0 ] == metakey [0 ].upper ():
188+ _logger .debug ('%s: %s' , metakey , value )
182189 workaround = 'none'
183190 try :
184191 workaround_config = _config .get ('remote-user' , 'workaround' )
You can’t perform that action at this time.
0 commit comments