Created
May 12, 2011 22:38
-
-
Save tilgovi/969619 to your computer and use it in GitHub Desktop.
gunicorn logging reload on USR1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py | |
index 6062117..a681420 100644 | |
--- a/gunicorn/app/base.py | |
+++ b/gunicorn/app/base.py | |
@@ -38,6 +38,7 @@ class Application(object): | |
self.callable = None | |
self.logger = None | |
self.do_load_config() | |
+ self.__handlers = None | |
def do_load_config(self): | |
try: | |
@@ -106,8 +107,7 @@ class Application(object): | |
self.do_load_config() | |
if self.cfg.spew: | |
debug.spew() | |
- loglevel = self.LOG_LEVELS.get(self.cfg.loglevel.lower(), logging.INFO) | |
- self.logger.setLevel(loglevel) | |
+ self.configure_logging() | |
def wsgi(self): | |
if self.callable is None: | |
@@ -148,6 +148,10 @@ class Application(object): | |
handlers.append(logging.FileHandler(self.cfg.logfile)) | |
else: | |
handlers.append(logging.StreamHandler()) | |
+ if self.__handlers: | |
+ for h in self.__handlers: | |
+ self.logger.removeHandler(h) | |
+ self.__handlers = handlers | |
loglevel = self.LOG_LEVELS.get(self.cfg.loglevel.lower(), logging.INFO) | |
self.logger.setLevel(loglevel) | |
diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py | |
index 5aa8a4c..9569cb3 100644 | |
--- a/gunicorn/arbiter.py | |
+++ b/gunicorn/arbiter.py | |
@@ -236,8 +236,10 @@ class Arbiter(object): | |
def handle_usr1(self): | |
"""\ | |
SIGUSR1 handling. | |
- Kill all workers by sending them a SIGUSR1 | |
+ Reload the logging configuration. | |
+ Kill all workers by sending them a SIGUSR1. | |
""" | |
+ self.app.configure_logging() | |
self.kill_workers(signal.SIGUSR1) | |
def handle_usr2(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment