Ticket #12012: 12012-r11603.diff
File 12012-r11603.diff, 8.1 KB (added by , 15 years ago) |
---|
-
django/__init__.py
diff --git a/django/__init__.py b/django/__init__.py index 2b87a7e..b92c1f4 100644
a b 1 from django.utils import log 2 1 3 VERSION = (1, 2, 0, 'alpha', 0) 2 4 3 5 def get_version(): -
django/conf/__init__.py
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 7bc7ae9..793c721 100644
a b class Settings(object): 108 108 os.environ['TZ'] = self.TIME_ZONE 109 109 time.tzset() 110 110 111 if getattr(self, 'LOGGING', None): 112 from django.utils import log 113 log.configure_from_dict(self.LOGGING) 114 111 115 def get_all_members(self): 112 116 return dir(self) 113 117 -
django/core/management/commands/runserver.py
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py index fc2c694..78798f1 100644
a b class Command(BaseCommand): 9 9 help='Tells Django to NOT use the auto-reloader.'), 10 10 make_option('--adminmedia', dest='admin_media_path', default='', 11 11 help='Specifies the directory from which to serve admin media.'), 12 make_option('--loglevel', dest='log_levels', action='append', 13 help='Set the minimum log level to be displayed at the console'), 12 14 ) 13 15 help = "Starts a lightweight Web server for development." 14 16 args = '[optional port number, or ipaddr:port]' … … class Command(BaseCommand): 39 41 use_reloader = options.get('use_reloader', True) 40 42 admin_media_path = options.get('admin_media_path', '') 41 43 shutdown_message = options.get('shutdown_message', '') 44 log_levels = options.get('log_levels', []) 42 45 quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' 43 46 47 if log_levels: 48 from django.utils.log import logger as django_logger 49 import logging 50 django_logger.addHandler(logging.StreamHandler()) 51 for log_level in log_levels: 52 try: 53 log_name, level = log_level.split(':') 54 except ValueError: 55 raise CommandError("Invalid log level specified") 56 if level.isdigit(): 57 level = int(level) 58 else: 59 level = getattr(logging, level.upper(), None) 60 if level is None: 61 raise CommandError("Invalid log level: %s" % level) 62 logging.getLogger(log_name).setLevel(level) 63 44 64 def inner_run(): 45 65 from django.conf import settings 46 66 from django.utils import translation 67 47 68 print "Validating models..." 48 69 self.validate(display_num_errors=True) 49 70 print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE) -
django/db/backends/__init__.py
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 9a1fe30..a183941 100644
a b class BaseDatabaseWrapper(local): 81 81 cursor = self._cursor() 82 82 if settings.DEBUG: 83 83 return self.make_debug_cursor(cursor) 84 return cursor84 return self.make_logging_cursor(cursor) 85 85 86 86 def make_debug_cursor(self, cursor): 87 87 return util.CursorDebugWrapper(cursor, self) 88 88 89 def make_logging_cursor(self, cursor): 90 return util.CursorLoggingWrapper(cursor, self) 91 89 92 class BaseDatabaseFeatures(object): 90 93 allows_group_by_pk = False 91 94 # True if django.db.backend.utils.typecast_timestamp is used on values -
django/db/backends/util.py
diff --git a/django/db/backends/util.py b/django/db/backends/util.py index f9c07a9..ca0043a 100644
a b 1 1 import datetime 2 2 from time import time 3 4 3 from django.utils.hashcompat import md5_constructor 4 import logging 5 logger = logging.getLogger('django.db.sql') 5 6 6 7 try: 7 8 import decimal 8 9 except ImportError: 9 10 from django.utils import _decimal as decimal # for Python 2.3 10 11 11 class CursorDebugWrapper(object): 12 class CursorWrapper(object): 13 def __init__(self, cursor, db): 14 self.cursor = cursor 15 self.db = db # Instance of a BaseDatabaseWrapper subclass 16 17 def __getattr__(self, attr): 18 if attr in self.__dict__: 19 return self.__dict__[attr] 20 else: 21 return getattr(self.cursor, attr) 22 23 def __iter__(self): 24 return iter(self.cursor) 25 26 class CursorLoggingWrapper(CursorWrapper): 27 def execute(self, sql, params=()): 28 start = time() 29 try: 30 return self.cursor.execute(sql, params) 31 finally: 32 stop = time() 33 sql = self.db.ops.last_executed_query(self.cursor, sql, params) 34 logger.info('%.3fs:\t%s' % (stop - start, sql)) 35 36 def executemany(self, sql, param_list): 37 start = time() 38 try: 39 return self.cursor.executemany(sql, param_list) 40 finally: 41 stop = time() 42 logger.info('%.3fs:\t%s' % (stop - start, sql)) 43 44 class CursorDebugWrapper(CursorWrapper): 12 45 def __init__(self, cursor, db): 13 46 self.cursor = cursor 14 47 self.db = db # Instance of a BaseDatabaseWrapper subclass … … class CursorDebugWrapper(object): 24 57 'sql': sql, 25 58 'time': "%.3f" % (stop - start), 26 59 }) 60 logger.info('%.3fs:\t%s' % (stop - start, sql)) 27 61 28 62 def executemany(self, sql, param_list): 29 63 start = time() … … class CursorDebugWrapper(object): 35 69 'sql': '%s times: %s' % (len(param_list), sql), 36 70 'time': "%.3f" % (stop - start), 37 71 }) 38 39 def __getattr__(self, attr): 40 if attr in self.__dict__: 41 return self.__dict__[attr] 42 else: 43 return getattr(self.cursor, attr) 44 45 def __iter__(self): 46 return iter(self.cursor) 72 logger.info('%.3fs:\t%s' % (stop - start, sql)) 47 73 48 74 ############################################### 49 75 # Converters from database (string) to Python # -
new file django/utils/log.py
diff --git a/django/utils/log.py b/django/utils/log.py new file mode 100644 index 0000000..21fd0aa
- + 1 from django.utils.importlib import import_module 2 from django.core.exceptions import ImproperlyConfigured 3 import logging 4 5 class NullHandler(logging.Handler): 6 def emit(self, record): 7 pass 8 9 logger = logging.getLogger('django') 10 logger.setLevel(logging.INFO) 11 if len(logger.handlers) == 0: 12 logger.addHandler(NullHandler()) 13 logger.propagate = False 14 15 def configure_from_dict(configuration): 16 "Configure loggers using a settings.LOGGING style dictionary" 17 for logger_label, config in configuration.items(): 18 logger = logging.getLogger(logger_label) 19 level = config.pop('level', None) 20 if level is not None: 21 if level.isdigit(): 22 level_int = int(level) 23 else: 24 level_int = getattr(logging, level.upper(), None) 25 if level_int is None: 26 raise ImproperlyConfigured, \ 27 '"%s" is not a valid logging level' % level 28 logger.setLevel(level_int) 29 handler = config.pop('handler', None) 30 if handler is not None: 31 klass = handler_from_string(handler) 32 logger.addHandler(klass(**config)) 33 34 def handler_from_string(string): 35 # Could refactor with django.core.handlers.base.BaseHandler.load_middleware 36 try: 37 dot = string.rindex('.') 38 except ValueError: 39 raise ImproperlyConfigured, '%s isn\'t a handler module' % string 40 module, classname = string[:dot], string[dot+1:] 41 try: 42 mod = import_module(module) 43 except ImportError, e: 44 raise ImproperlyConfigured, 'Error importing handler %s: "%s"' % (module, e) 45 try: 46 klass = getattr(mod, classname) 47 except AttributeError: 48 raise ImproperlyConfigured, 'Module "%s" does not define a "%s" class' % (module, classname) 49 return klass