Ticket #14800: optional-14800.diff

File optional-14800.diff, 3.2 KB (added by Horst Gutmann, 5 years ago)

Verbose logging as option

  • django/core/management/commands/runserver.py

    diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
    index 0ca15fd..2234520 100644
    a b class Command(BaseCommand): 
    2626            help='Tells Django to NOT use threading.'),
    2727        make_option('--noreload', action='store_false', dest='use_reloader', default=True,
    2828            help='Tells Django to NOT use the auto-reloader.'),
     29        make_option('--verbose-logging', action='store_true', dest='verbose_logging', default=False,
     30            help='Tells Django to log all requests including those to admin media files and /favicon.ico'),
    2931    )
    3032    help = "Starts a lightweight Web server for development."
    3133    args = '[optional port number, or ipaddr:port]'
    class Command(BaseCommand): 
    111113        try:
    112114            handler = self.get_handler(*args, **options)
    113115            run(self.addr, int(self.port), handler,
    114                 ipv6=self.use_ipv6, threading=threading)
     116                ipv6=self.use_ipv6, threading=threading,
     117                verbose_logging=options.get('verbose_logging', False))
    115118        except WSGIServerException as e:
    116119            # Use helpful error messages instead of ugly tracebacks.
    117120            ERRORS = {
  • django/core/servers/basehttp.py

    diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
    index 89ec2b3..5db55ef 100644
    a b class WSGIServer(simple_server.WSGIServer, object): 
    126126
    127127
    128128class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
     129    verbose_logging = False
    129130
    130131    def __init__(self, *args, **kwargs):
    131132        from django.conf import settings
    class WSGIRequestHandler(simple_server.WSGIRequestHandler, object): 
    142143
    143144    def log_message(self, format, *args):
    144145        # Don't bother logging requests for admin images or the favicon.
    145         if (self.path.startswith(self.admin_static_prefix)
    146                 or self.path == '/favicon.ico'):
     146        if not self.verbose_logging and (
     147                (self.path.startswith(self.admin_static_prefix)
     148                or self.path == '/favicon.ico')):
    147149            return
    148150
    149151        msg = "[%s] %s\n" % (self.log_date_time_string(), format % args)
    class WSGIRequestHandler(simple_server.WSGIRequestHandler, object): 
    169171        sys.stderr.write(msg)
    170172
    171173
    172 def run(addr, port, wsgi_handler, ipv6=False, threading=False):
     174def get_request_handler(**options):
     175    handler_cls = WSGIRequestHandler
     176    if not options.get('verbose_logging', False):
     177        return handler_cls
     178    return type(str('WSGIRequestHandler'), (handler_cls,), options)
     179
     180
     181def run(addr, port, wsgi_handler, ipv6=False, threading=False,
     182        verbose_logging=False):
    173183    server_address = (addr, port)
    174184    if threading:
    175185        httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
    176186    else:
    177187        httpd_cls = WSGIServer
    178     httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
     188    httpd = httpd_cls(server_address,
     189        get_request_handler(verbose_logging=verbose_logging),
     190        ipv6=ipv6)
    179191    httpd.set_app(wsgi_handler)
    180192    httpd.serve_forever()
Back to Top