Scrapy, a fast high-level web crawling & scraping framework for Python.
Parametrize log formatting strings
Julia Medinaccdd8bfbccdd
diff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex 7deb6e0c6..3936c04b8 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -612,6 +612,31 @@ Default: ``None``File name to use for logging output. If None, standard error will be used.+.. setting:: LOG_FORMAT++LOG_FORMAT+----------++Default: ``'%(asctime)s [%(name)s] %(levelname)s: %(message)s'``++String for formatting log messsages. Refer to the `Python logging documentation`_ for the whole list of available+placeholders.++.. _Python logging documentation: https://docs.python.org/2/library/logging.html#logrecord-attributes++.. setting:: LOG_DATEFORMAT++LOG_DATEFORMAT+--------------++Default: ``'%Y-%m-%d %H:%M:%S%z'``++String for formatting date/time, expansion of the ``%(asctime)s`` placeholder+in :setting:`LOG_FORMAT`. Refer to the `Python datetime documentation`_ for the whole list of available+directives.++.. _Python datetime documentation: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior+.. setting:: LOG_LEVELLOG_LEVELdiff --git a/scrapy/settings/default_settings.py b/scrapy/settings/default_settings.pyindex 49addbc81..0c3d7c5bd 100644--- a/scrapy/settings/default_settings.py+++ b/scrapy/settings/default_settings.py@@ -167,6 +167,8 @@ ITEM_PIPELINES_BASE = {}LOG_ENABLED = TrueLOG_ENCODING = 'utf-8'LOG_FORMATTER = 'scrapy.logformatter.LogFormatter'+LOG_FORMAT = '%(asctime)s [%(name)s] %(levelname)s: %(message)s'+LOG_DATEFORMAT = '%Y-%m-%d %H:%M:%S%z'LOG_STDOUT = FalseLOG_LEVEL = 'DEBUG'LOG_FILE = Nonediff --git a/scrapy/utils/log.py b/scrapy/utils/log.pyindex 27cc7b227..e2b1edcf7 100644--- a/scrapy/utils/log.py+++ b/scrapy/utils/log.py@@ -86,8 +86,8 @@ def configure_logging(settings=None):handler = logging.NullHandler()formatter = logging.Formatter(- fmt='%(asctime)s [%(name)s] %(levelname)s: %(message)s',- datefmt='%Y-%m-%d %H:%M:%S%z'+ fmt=settings.get('LOG_FORMAT'),+ datefmt=settings.get('LOG_DATEFORMAT'))handler.setFormatter(formatter)handler.setLevel(settings.get('LOG_LEVEL'))