mirror of https://github.com/scrapy/scrapy.git
enable settings.LOGGING to benefit dictConfig
This commit is contained in:
parent
a152c066fa
commit
c4939f464b
|
|
@ -92,34 +92,29 @@ def configure_logging(settings=None, install_root_handler=True):
|
|||
if isinstance(settings, dict) or settings is None:
|
||||
settings = Settings(settings)
|
||||
|
||||
LOGGING_FROM_SETTINGS = settings.get('LOGGING')
|
||||
|
||||
if settings.getbool('LOG_STDOUT'):
|
||||
sys.stdout = StreamLogger(logging.getLogger('stdout'))
|
||||
LOGGING_FROM_SETTINGS = None
|
||||
|
||||
if install_root_handler:
|
||||
elif LOGGING_FROM_SETTINGS:
|
||||
LOGGING = DEFAULT_LOGGING.copy()
|
||||
LOGGING.update(LOGGING_FROM_SETTINGS)
|
||||
dictConfig(LOGGING)
|
||||
|
||||
if install_root_handler and not LOGGING_FROM_SETTINGS:
|
||||
logging.root.setLevel(logging.NOTSET)
|
||||
handler = _get_handler(settings)
|
||||
logging.root.addHandler(handler)
|
||||
|
||||
|
||||
def _import_hander(name):
|
||||
"""Return class from dotted name"""
|
||||
import importlib
|
||||
module_name, class_name = name.rsplit('.', 1)
|
||||
module = importlib.import_module(module_name)
|
||||
return getattr(module, class_name)
|
||||
|
||||
|
||||
def _get_handler(settings):
|
||||
""" Return a log handler object according to settings """
|
||||
filename = settings.get('LOG_FILE')
|
||||
if filename:
|
||||
encoding = settings.get('LOG_ENCODING')
|
||||
handler = settings.get('LOG_HANDLER')
|
||||
if handler:
|
||||
Handler = _import_hander(handler)
|
||||
else:
|
||||
Handler = logging.FileHandler
|
||||
handler = Handler(filename, encoding=encoding)
|
||||
handler = logging.FileHandler(filename, encoding=encoding)
|
||||
elif settings.getbool('LOG_ENABLED'):
|
||||
handler = logging.StreamHandler()
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue