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.
This commit is contained in:
benoitc 2012-09-21 08:29:24 +02:00
parent 1362132162
commit f47d100446
2 changed files with 34 additions and 5 deletions

View File

@ -1,5 +1,5 @@
[loggers] [loggers]
keys=root, gunicorn_error, gunicorn_access keys=root, gunicon.error, gunicon.access
[handlers] [handlers]
keys=console, error_file, access_file keys=console, error_file, access_file
@ -11,16 +11,16 @@ keys=generic, access
level=INFO level=INFO
handlers=console handlers=console
[logger_gunicorn_error] [logger_gunicon.error]
level=INFO level=INFO
handlers=error_file handlers=error_file
propagate=1 propagate=1
qualname=gunicorn.error qualname=gunicorn.error
[logger_gunicorn_access] [logger_gunicon.access]
level=INFO level=INFO
handlers=access_file handlers=access_file
propagate=1 propagate=0
qualname=gunicorn.access qualname=gunicorn.access
[handler_console] [handler_console]

View File

@ -18,6 +18,34 @@ except ImportError:
from gunicorn import util 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(): def loggers():
""" get list of all loggers """ """ get list of all loggers """
@ -126,7 +154,8 @@ class Logger(object):
fmt=logging.Formatter(self.access_fmt)) fmt=logging.Formatter(self.access_fmt))
else: else:
if os.path.exists(cfg.logconfig): if os.path.exists(cfg.logconfig):
fileConfig(cfg.logconfig) fileConfig(cfg.logconfig, defaults=CONFIG_DEFAULTS,
disable_existing_loggers=False)
else: else:
raise RuntimeError("Error: log config '%s' not found" % cfg.logconfig) raise RuntimeError("Error: log config '%s' not found" % cfg.logconfig)