@@ -231,10 +231,10 @@ Logging
231
231
Most errors (unsupported CSS property, missing image, ...)
232
232
are not fatal and will not prevent a document from being rendered.
233
233
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:
238
238
239
239
.. code-block :: python
240
240
@@ -243,6 +243,24 @@ configuring the ``weasyprint`` logger object:
243
243
logger.handlers = [] # Remove the default stderr handler
244
244
logger.addHandler(logging.FileHandler(' /path/to/weasyprint.log' ))
245
245
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
+
246
264
See the documentation of the :mod: `logging ` module for details.
247
265
248
266
0 commit comments