Send WeasyPrint logs to Sphinx logger

This commit is contained in:
Kujiu 2020-06-17 20:25:21 +02:00
parent 76baca06b4
commit 441ec2418e
Signed by: kujiu
GPG key ID: ABBB2CAC6855599F
7 changed files with 39 additions and 5 deletions

View file

@ -87,7 +87,7 @@ Following parameters are needed to sign:
Signing methods are really limited. Do not Signing methods are really limited. Do not
hesitate to contribute ! hesitate to contribute !
Available: `none` (no encryption), `pkcs11` Available: `none` (no signing), `pkcs11`
To be implemented: `p12`, `gpg` To be implemented: `p12`, `gpg`

View file

@ -9,6 +9,10 @@ from sphinx.util.osutil import os_path
from sphinx.locale import __ from sphinx.locale import __
import weasyprint import weasyprint
from .loghandler import init_wpsphinx_log
init_wpsphinx_log()
class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): class WeasyPrintPDFBuilder(SingleFileHTMLBuilder):
@ -70,7 +74,5 @@ class WeasyPrintPDFBuilder(SingleFileHTMLBuilder):
self.config.weasyprint_basename + '.pdf' self.config.weasyprint_basename + '.pdf'
) )
weasy_html = weasyprint.HTML(infile) weasy_html = weasyprint.HTML(infile)
print('*********************')
print('%s ----- %s', (infile, outfile))
weasy_html.write_pdf(outfile) weasy_html.write_pdf(outfile)
# progress_message('Signing PDF') # progress_message('Signing PDF')

View file

@ -0,0 +1,30 @@
#!/usr/bin/env python3
import logging
from sphinx.util import logging as sphinx_logging
logger = sphinx_logging.getLogger('weasyprint_builder')
def init_wpsphinx_log():
"""
Initialize logging for WeasyPrint.
"""
wplogger = logging.getLogger('weasyprint')
wphandler = SphinxWPHandler()
wphandler.setLevel(logging.INFO)
formatter = logging.Formatter('%(message)s')
wphandler.setFormatter(formatter)
wplogger.addHandler(wphandler)
class SphinxWPHandler(logging.StreamHandler):
"""
Resend WeasyPrint logging to Sphinx output.
"""
def __init__(self):
super(SphinxWPHandler, self).__init__()
def emit(self, record):
logger.handle(record)

View file

@ -9,6 +9,10 @@ from sphinx.util.osutil import os_path
from sphinx.locale import __ from sphinx.locale import __
import weasyprint import weasyprint
from .loghandler import init_wpsphinx_log
init_wpsphinx_log()
class WeasyPrintPDFBuilder(SingleFileHTMLBuilder): class WeasyPrintPDFBuilder(SingleFileHTMLBuilder):
@ -70,7 +74,5 @@ class WeasyPrintPDFBuilder(SingleFileHTMLBuilder):
self.config.weasyprint_basename + '.pdf' self.config.weasyprint_basename + '.pdf'
) )
weasy_html = weasyprint.HTML(infile) weasy_html = weasyprint.HTML(infile)
print('*********************')
print('%s ----- %s', (infile, outfile))
weasy_html.write_pdf(outfile) weasy_html.write_pdf(outfile)
# progress_message('Signing PDF') # progress_message('Signing PDF')