From e5de977878772ebe97d5606489511260da68dadc Mon Sep 17 00:00:00 2001 From: Michal Fapso Date: Thu, 30 Oct 2025 14:34:49 +0100 Subject: [PATCH] added option weasyprint_log_path --- src/mkdocs_to_pdf/options.py | 2 ++ src/mkdocs_to_pdf/plugin.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/mkdocs_to_pdf/options.py b/src/mkdocs_to_pdf/options.py index b0d49609..666870e9 100644 --- a/src/mkdocs_to_pdf/options.py +++ b/src/mkdocs_to_pdf/options.py @@ -20,6 +20,7 @@ class Options(object): ('output_path', config_options.Type(str, default="pdf/document.pdf")), ('html_path', config_options.Type(str, default=None)), ('theme_handler_path', config_options.Type(str, default=None)), + ('weasyprint_log_path', config_options.Type(str, default='')), ('author', config_options.Type(str, default='')), ('copyright', config_options.Type(str, default='')), @@ -59,6 +60,7 @@ def __init__(self, local_config, config, logger: logging): self.output_path = local_config['output_path'] self.html_path = local_config.get('html_path', None) self.theme_handler_path = local_config.get('theme_handler_path', None) + self.weasyprint_log_path = local_config['weasyprint_log_path'] # Author and Copyright self._author = local_config['author'] or config['site_author'] or '' diff --git a/src/mkdocs_to_pdf/plugin.py b/src/mkdocs_to_pdf/plugin.py index 63e21ab2..d5105247 100644 --- a/src/mkdocs_to_pdf/plugin.py +++ b/src/mkdocs_to_pdf/plugin.py @@ -88,6 +88,12 @@ def on_config(self, config): else: LOGGER.setLevel(logging.ERROR) + if self._options.weasyprint_log_path: + open(self._options.weasyprint_log_path, 'w').close() # Logger appends to the file by default so we have to clear it explicitly + handler = logging.FileHandler(self._options.weasyprint_log_path) + handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) + LOGGER.addHandler(handler) + if self._options.strict: self._error_counter = _ErrorAndWarningCountFilter() LOGGER.addFilter(self._error_counter)