Parametrize log formatting strings

This commit is contained in:
Julia Medina 2015-03-05 05:04:21 -03:00
parent 21b9f377d6
commit ccdd8bfbcc
3 changed files with 29 additions and 2 deletions

View File

@ -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_LEVEL
LOG_LEVEL

View File

@ -167,6 +167,8 @@ ITEM_PIPELINES_BASE = {}
LOG_ENABLED = True
LOG_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 = False
LOG_LEVEL = 'DEBUG'
LOG_FILE = None

View File

@ -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'))