Permalink
Browse files

Add documentation on logged rendering steps

Related to #488.
  • Loading branch information...
liZe committed Aug 26, 2017
1 parent bb3a4db commit a7b17fb924f83a7270b25af02f1137491c2eafc2
Showing with 22 additions and 4 deletions.
  1. +22 −4 docs/tutorial.rst
View
@@ -231,10 +231,10 @@ Logging
Most errors (unsupported CSS property, missing image, ...)
are not fatal and will not prevent a document from being rendered.
WeasyPrint uses the :mod:`logging` module from the Python standard library
to log these errors and let you know about them.
Logged messaged will go to *stderr* by default. You can change that by
configuring the ``weasyprint`` logger object:
WeasyPrint uses the :mod:`logging` module from the Python standard library to
log these errors and let you know about them. When WeasyPrint is launched in a
terminal, logged messaged will go to *stderr* by default. You can change that
by configuring the ``weasyprint`` logger object:
.. code-block:: python
@@ -243,6 +243,24 @@ configuring the ``weasyprint`` logger object:
logger.handlers = [] # Remove the default stderr handler
logger.addHandler(logging.FileHandler('/path/to/weasyprint.log'))
The ``INFO`` level is used to report the rendering progress. It is useful to
get feedback when WeasyPrint is launched in a terminal (using the ``--verbose``
option), or to give this feedback to end users when used as a library. To catch
these logs, you can for example use a filter:
.. code-block:: python
import logging
class LoggerFilter(logging.Filter):
def filter(self, record):
if record.level == logging.INFO:
print(record.getMessage())
return False
logger = logging.getLogger('weasyprint')
logger.addFilter(LoggerFilter())
See the documentation of the :mod:`logging` module for details.

0 comments on commit a7b17fb

Please sign in to comment.