pythonconsoleweasyprint

Silent WeasyPrint script run


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?


Solution

  • 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.