Scrapy, a fast high-level web crawling & scraping framework for Python.
make suggested changes.
Anubhav Patel82049e9c41f8
diff --git a/docs/topics/logging.rst b/docs/topics/logging.rstindex 72f24bae6..006530a8c 100644--- a/docs/topics/logging.rst+++ b/docs/topics/logging.rst@@ -193,11 +193,13 @@ to override some of the Scrapy settings regarding logging.Module `logging.handlers <https://docs.python.org/2/library/logging.handlers.html>`_Further documentation on available handlers+.. _custom-log-formats:+Custom Log Formats--------------------+-------------------Custom log format can be set for different actions by extending :class:`~scrapy.logformatter.LogFormatter` class-and making :setting:`LOG_FORMATTER` inside ``settings.py`` point to your new class.+A custom log format can be set for different actions by extending :class:`~scrapy.logformatter.LogFormatter` class+and making :setting:`LOG_FORMATTER` point to your new class... autoclass:: scrapy.logformatter.LogFormatter:members:diff --git a/docs/topics/settings.rst b/docs/topics/settings.rstindex 1dfb5b8aa..a36c0b34c 100644--- a/docs/topics/settings.rst+++ b/docs/topics/settings.rst@@ -871,9 +871,9 @@ directives.LOG_FORMATTER--------------Default: ``scrapy.logformatter.LogFormatter``+Default: :class:`scrapy.logformatter.LogFormatter`-The class to use for formatting log messages for different actions.+The class to use for :ref:`formatting log messages <custom-log-formats>` for different actions... setting:: LOG_LEVELdiff --git a/scrapy/logformatter.py b/scrapy/logformatter.pyindex 0bb8aee58..17c69cba8 100644--- a/scrapy/logformatter.py+++ b/scrapy/logformatter.py@@ -30,12 +30,24 @@ class LogFormatter(object):* ``args`` should be a tuple or dict with the formatting placeholders for ``msg``. The final log message iscomputed as ``msg % args``.+ Here is an example on how to create a custom log formatter to lower the severity level of the log message+ when an item is dropped from the pipeline::++ class PoliteLogFormatter(logformatter.LogFormatter):+ def dropped(self, item, exception, response, spider):+ return {+ 'level': logging.INFO, # lowering the level from logging.WARNING+ 'msg': u"Dropped: %(exception)s" + os.linesep + "%(item)s",+ 'args': {+ 'exception': exception,+ 'item': item,+ }+ }+"""def crawled(self, request, response, spider):- """- ``crawled`` is called to log message when the crawler finds a webpage.- """+ """Logs a message when the crawler finds a webpage."""request_flags = ' %s' % str(request.flags) if request.flags else ''response_flags = ' %s' % str(response.flags) if response.flags else ''return {@@ -53,9 +65,7 @@ class LogFormatter(object):}def scraped(self, item, response, spider):- """- ``scraped`` is called to log message when an item is scraped by a spider.- """+ """Logs a message when an item is scraped by a spider."""if isinstance(response, Failure):src = response.getErrorMessage()else:@@ -70,9 +80,7 @@ class LogFormatter(object):}def dropped(self, item, exception, response, spider):- """- ``dropped`` is called to log message when an item is dropped while it is passing through the item pipeline.- """+ """Logs a message when an item is dropped while it is passing through the item pipeline."""return {'level': logging.WARNING,'msg': DROPPEDMSG,