Sorry for the late answer.

Enrico Zini <enr...@debian.org> wrote:
> I'd like to run a bottle server without it spewing messages to
> stdout/stderr. For that, I need to turn off the welcome code here:
> [...]
> Note that in order to do it, one just needs to pass quiet=True. Great.
> Except, it uses kargs.get instead of kargs.pop, therefore leaving quiet
> in the args that are passed to the server constructor 3 lines later.

Fixed in 64220991fee3791a4c8128537253ea3617450963

> Just for the record, here is the gist on how to silence that from
> Bottle:
> 
> class WSGIRefServer(ServerAdapter):
>     def run(self, handler): # pragma: no cover
>         from wsgiref.simple_server import make_server, WSGIRequestHandler
>         class QuietHandler(WSGIRequestHandler):
>             def log_request(*args, **kw):
>                 pass
>         srv = make_server(self.host, self.port, handler,
> handler_class=QuietHandler)
>         srv.serve_forever()

Added in be9565f6445ae90055c15da3f6663fb8f078cea5

Am Dienstag, den 15.06.2010, 17:28 +0200 schrieb David Paleino:
> Maybe we can do something like that from Bottle's side, to have a consistent
> "quiet=True" behaviour between the various adapters? (i.e. total silence, with
> no output whatsoever, and maybe proper logging) -- I know it's a hack, but
> better than waiting for the other N servers out there to be fixed.

The ServerAdapter api is quite limited. It is a fast way to get the
application up and running, but not much more. For any non-trivial
deployment scenarios I'd use the WSGI api directly and configure the
server myself. We could improve the documentation on this one, though.

-- 
Mit freundlichen Grüßen
Marcel Hellkamp
>From be9565f6445ae90055c15da3f6663fb8f078cea5 Mon Sep 17 00:00:00 2001
From: Marcel Hellkamp <m...@gsites.de>
Date: Fri, 18 Jun 2010 23:21:44 +0200
Subject: [PATCH 2/2] Silence WSGIRefServer on run(quiet=True).

---
 bottle.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/bottle.py b/bottle.py
index 2d88602..fef1837 100755
--- a/bottle.py
+++ b/bottle.py
@@ -1201,8 +1201,12 @@ class FlupFCGIServer(ServerAdapter):
 
 class WSGIRefServer(ServerAdapter):
     def run(self, handler): # pragma: no cover
-        from wsgiref.simple_server import make_server
-        srv = make_server(self.host, self.port, handler)
+        from wsgiref.simple_server import make_server, WSGIRequestHandler
+        if self.quiet:
+            class QuietHandler(WSGIRequestHandler):
+                def log_request(*args, **kw): pass
+            self.options['handler_class'] = QuietHandler
+        srv = make_server(self.host, self.port, handler, **self.options)
         srv.serve_forever()
 
 
-- 
1.7.0.4

>From 64220991fee3791a4c8128537253ea3617450963 Mon Sep 17 00:00:00 2001
From: Marcel Hellkamp <m...@gsites.de>
Date: Fri, 18 Jun 2010 23:11:11 +0200
Subject: [PATCH 1/2] fix: Calling run(quiet=True) broke some of the server adapters.

---
 bottle.py |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/bottle.py b/bottle.py
index 30f518c..2d88602 100755
--- a/bottle.py
+++ b/bottle.py
@@ -1316,7 +1316,7 @@ class AutoServer(ServerAdapter):
 
 
 def run(app=None, server=WSGIRefServer, host='127.0.0.1', port=8080,
-        interval=1, reloader=False, **kargs):
+        interval=1, reloader=False, quiet=False, **kargs):
     """ Runs bottle as a web server. """
     app = app if app else default_app()
     # Instantiate server, if it is a class instead of an instance
@@ -1324,8 +1324,8 @@ def run(app=None, server=WSGIRefServer, host='127.0.0.1', port=8080,
         server = server(host=host, port=port, **kargs)
     if not isinstance(server, ServerAdapter):
         raise RuntimeError("Server must be a subclass of WSGIAdapter")
-    quiet = kargs.get('quiet', False) or server.quiet
-    if not quiet: # pragma: no cover
+    server.quiet = server.quiet or quiet
+    if not server.quiet: # pragma: no cover
         if not reloader or os.environ.get('BOTTLE_CHILD') == 'true':
             print "Bottle server starting up (using %s)..." % repr(server)
             print "Listening on http://%s:%d/"; % (server.host, server.port)
@@ -1339,7 +1339,7 @@ def run(app=None, server=WSGIRefServer, host='127.0.0.1', port=8080,
         else:
             server.run(app)
     except KeyboardInterrupt:
-        if not quiet: # pragma: no cover
+        if not server.quiet: # pragma: no cover
             print "Shutting Down..."
 
 
-- 
1.7.0.4

Reply via email to