Issue 1087: support dictConfig logging configuration

This commit is contained in:
Mat Moore 2015-09-03 16:02:00 +01:00 committed by Randall Leeds
parent ccad26dd91
commit e6de1a07b4
2 changed files with 19 additions and 2 deletions

View File

@ -1309,6 +1309,19 @@ class LogConfig(Setting):
""" """
class LogConfigDict(Setting):
name = "logconfig_dict"
section = "Logging"
validator = validate_dict
default = {}
desc = """\
The log config dictionary to use, using the standard Python logging
module's dictConfig format.
If specified, this takes precedence over logconfig, which uses the older
fileConfig format.
"""
class SyslogTo(Setting): class SyslogTo(Setting):
name = "syslog_addr" name = "syslog_addr"
section = "Logging" section = "Logging"

View File

@ -8,7 +8,7 @@ import binascii
import time import time
import logging import logging
logging.Logger.manager.emittedNoHandlerWarning = 1 logging.Logger.manager.emittedNoHandlerWarning = 1
from logging.config import fileConfig from logging.config import fileConfig, dictConfig
import os import os
import socket import socket
import sys import sys
@ -226,7 +226,11 @@ class Logger(object):
self.access_log, cfg, self.syslog_fmt, "access" self.access_log, cfg, self.syslog_fmt, "access"
) )
if cfg.logconfig: if cfg.logconfig_dict:
config = CONFIG_DEFAULTS.copy()
config.update(cfg.logconfig_dict)
dictConfig(config)
elif cfg.logconfig:
if os.path.exists(cfg.logconfig): if os.path.exists(cfg.logconfig):
defaults = CONFIG_DEFAULTS.copy() defaults = CONFIG_DEFAULTS.copy()
defaults['__file__'] = cfg.logconfig defaults['__file__'] = cfg.logconfig