6

WeasyPrint doesn't support some of the CSS3 features (yet, I hope), and running a Python script throws a long list of ignored entries (eg. box shadows, gradients), then a job summary. Is it possible to run WeasyPrint in silent mode, without any information shown?

Chris
  • 63
  • 1
  • 6

2 Answers2

6

With WeasyPrint, I noticed that most of its log messages in my webserver.error.log file were actually from 'fontTools', which is imported and used by 'weasyprint', eg:

head pruned
OS/2 Unicode ranges pruned: [0]
glyf pruned
GDEF pruned
GPOS pruned
GSUB pruned

After I 'import weasyprint', which imports 'fontTools', the 'fontTools' logger level is set to INFO:

print(logging.getLogger('fontTools'))

<Logger fontTools (INFO)>

So if I use:

import weasyprint, logging
logging.getLogger('fontTools').setLevel(logging.WARNING)
logging.getLogger('weasyprint').setLevel(logging.WARNING)

this stops the INFO messages appearing in my webserver.error.log file.

Optionally could use: '.....setLevel(logging.ERROR)' to also remove the WARNING messages.

3

According to the documentation, you can create a new logger object to override WeasyPrint default behavior. The following code snippet is taken from the documentation page itself.

import logging
logger = logging.getLogger('weasyprint')
logger.handlers = []  # Remove the default stderr handler
logger.addHandler(logging.FileHandler('/path/to/weasyprint.log'))

If you don't want any logging at all, you can remove the last line.

Anonymous
  • 11,740
  • 3
  • 40
  • 50
Hai Vu
  • 37,849
  • 11
  • 66
  • 93
  • 1
    Thanks, that did the trick. Setting a high logging level with `logger.setLevel(40)` keeps the log file clear for important errors. – Chris Sep 24 '15 at 15:51