From f47d1004462ebf9609ee5dac4ff6d9f5fb949787 Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 21 Sep 2012 08:29:24 +0200 Subject: [PATCH] initialize the logging config file with defaults. Set correct default to the logging config file so we are able to use our own loggers. While I'm here fix the example. --- examples/logging.conf | 8 ++++---- gunicorn/glogging.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/logging.conf b/examples/logging.conf index 48f1328f..ab1672df 100644 --- a/examples/logging.conf +++ b/examples/logging.conf @@ -1,5 +1,5 @@ [loggers] -keys=root, gunicorn_error, gunicorn_access +keys=root, gunicon.error, gunicon.access [handlers] keys=console, error_file, access_file @@ -11,16 +11,16 @@ keys=generic, access level=INFO handlers=console -[logger_gunicorn_error] +[logger_gunicon.error] level=INFO handlers=error_file propagate=1 qualname=gunicorn.error -[logger_gunicorn_access] +[logger_gunicon.access] level=INFO handlers=access_file -propagate=1 +propagate=0 qualname=gunicorn.access [handler_console] diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index f4c4a1ec..027c048d 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -18,6 +18,34 @@ except ImportError: from gunicorn import util +CONFIG_DEFAULTS = dict( + version = 1, + disable_existing_loggers = False, + + loggers = { + "root": { "level": "INFO", "handlers": ["console"] }, + "gunicorn.error": { + "level": "INFO", + "handlers": ["console"], + "propagate": True, + "qualname": "gunicorn.error" + } + }, + handlers = { + "console": { + "class": "logging.StreamHandler", + "formatter": "generic", + "stream": "sys.stdout" + } + }, + formatters = { + "generic": { + "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", + "datefmt": "%Y-%m-%d %H:%M:%S", + "class": "logging.Formatter" + } + } +) def loggers(): """ get list of all loggers """ @@ -126,7 +154,8 @@ class Logger(object): fmt=logging.Formatter(self.access_fmt)) else: if os.path.exists(cfg.logconfig): - fileConfig(cfg.logconfig) + fileConfig(cfg.logconfig, defaults=CONFIG_DEFAULTS, + disable_existing_loggers=False) else: raise RuntimeError("Error: log config '%s' not found" % cfg.logconfig)