bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.44k stars 1.47k forks source link

GeventServer ignores "log" keyword arg #725

Open peter9477 opened 9 years ago

peter9477 commented 9 years ago

The current code in GeventServer effectively ignores a keyword arg of "log", overwriting it either with "default" or None depending on the state of "self.quiet".

The expected behavior is that if self.quiet is not true, a log argument can be passed down to the WSGIServer. WSGIServer already has log="default" in its keyword args so the adapter doesn't need to, and should not, supply this explicitly itself.

Current code:

self.options['log'] = None if self.quiet else 'default'

Suggested new code:

if self.quiet: self.options['log'] = None

Edit: I should note, this applies to bottle 0.12 (and the latest code in master), and gevent 1.0.1. Earlier gevent (I checked 5c11789cabcc0cf737313cb0fdcb727a8dc38629 from 2011) would output to stderr if "log=None" so the current code in bottle would be broken for that version anyway (i.e. quiet=True would not actually silence the log output).

parasyte commented 7 years ago

FWIW, here's my workaround for this issue. Not a complete example, but it shows the relevant parts.

import bottle
import gevent.pywsgi

_WSGIServer = gevent.pywsgi.WSGIServer
class GeventWSGIServer(_WSGIServer):
    def __init__(self, *args, **kwargs):
        """
        XXX: workaround for https://github.com/bottlepy/bottle/issues/725
        """
        kwargs['log'] = kwargs['access_log']
        del kwargs['access_log']

        _WSGIServer.__init__(self, *args, **kwargs)
gevent.pywsgi.WSGIServer = GeventWSGIServer

app = bottle.Bottle()
bottle.run(
    app,
    server=bottle.GeventServer,
    handler_class=gevent.pywsgi.WSGIHandler,
    access_log=logging.getLogger(__name__)
)
defnull commented 7 years ago

Pull requests welcome.