Skip to content

Commit a7b17fb

Browse files
committed
Add documentation on logged rendering steps
Related to #488.
1 parent bb3a4db commit a7b17fb

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docs/tutorial.rst

+22-4
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ Logging
231231
Most errors (unsupported CSS property, missing image, ...)
232232
are not fatal and will not prevent a document from being rendered.
233233

234-
WeasyPrint uses the :mod:`logging` module from the Python standard library
235-
to log these errors and let you know about them.
236-
Logged messaged will go to *stderr* by default. You can change that by
237-
configuring the ``weasyprint`` logger object:
234+
WeasyPrint uses the :mod:`logging` module from the Python standard library to
235+
log these errors and let you know about them. When WeasyPrint is launched in a
236+
terminal, logged messaged will go to *stderr* by default. You can change that
237+
by configuring the ``weasyprint`` logger object:
238238

239239
.. code-block:: python
240240
@@ -243,6 +243,24 @@ configuring the ``weasyprint`` logger object:
243243
logger.handlers = [] # Remove the default stderr handler
244244
logger.addHandler(logging.FileHandler('/path/to/weasyprint.log'))
245245
246+
The ``INFO`` level is used to report the rendering progress. It is useful to
247+
get feedback when WeasyPrint is launched in a terminal (using the ``--verbose``
248+
option), or to give this feedback to end users when used as a library. To catch
249+
these logs, you can for example use a filter:
250+
251+
.. code-block:: python
252+
253+
import logging
254+
255+
class LoggerFilter(logging.Filter):
256+
def filter(self, record):
257+
if record.level == logging.INFO:
258+
print(record.getMessage())
259+
return False
260+
261+
logger = logging.getLogger('weasyprint')
262+
logger.addFilter(LoggerFilter())
263+
246264
See the documentation of the :mod:`logging` module for details.
247265

248266

0 commit comments

Comments
 (0)