util:wsgi: If we're logging to a file, shift libbe.LOG too
authorW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 07:43:53 +0000 (02:43 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 07:43:53 +0000 (02:43 -0500)
This avoids attempts to log to stderr if we're daemonizing the server.

libbe/util/wsgi.py

index 8f407e45031a72c2dcbde052c61d0c35e564919f..b731ec80fe1f58c857fdeb654e844c3fbd4bed63 100644 (file)
@@ -58,6 +58,7 @@ try:
 except ImportError:
     OpenSSL = None
 
+import libbe
 import libbe.command
 import libbe.command.base
 import libbe.command.util
@@ -686,6 +687,10 @@ class ServerCommand (libbe.command.base.Command):
             handler = logging.handlers.TimedRotatingFileHandler(
                 path, when='w6', interval=1, backupCount=4,
                 encoding=libbe.util.encoding.get_text_file_encoding())
+            while libbe.LOG.handlers:
+                handler = libbe.LOG.handlers[0]
+                libbe.LOG.removeHandler(handler)
+            libbe.LOG.addHandler(handler)
         else:
             handler = logging.StreamHandler(self.stdout)
         handler.setFormatter(logging.Formatter('%(message)s'))