The other solutions were not working for me. Here a more harsh hack, that does the job for me (I'm using weasyprint version 64.0
):
import logging
import logging.config
from weasyprint import HTML
# Setup logging configuration
LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "%(levelname)s %(asctime)s %(filename)s %(message)s"
},
},
"handlers": {
"null_handler": {
"class": "logging.NullHandler",
},
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "simple",
"stream": "ext://sys.stdout", # Default to standard output
},
},
"loggers": {
"fontTools": {
"level": "ERROR", # Suppress DEBUG and INFO for fontTools
"handlers": ["null_handler"],
"propagate": False
}
},
"root": {
"handlers": ["console"],
"level": "INFO", # Global level set to INFO
},
}
logging.config.dictConfig(LOGGING_CONFIG)
# Retrieve the logger for fontTools
fonttools_logger = logging.getLogger('fontTools')
# Check if the logger has handlers
has_handlers = bool(fonttools_logger.handlers)
# Print basic configuration details
print(f"Logger for fontTools found: {'Yes' if fonttools_logger else 'No'}")
print(f"Logger level: {logging.getLevelName(fonttools_logger.level)}")
print(f"Has handlers: {'Yes' if has_handlers else 'No'}")
print("Handlers attached to fontTools logger:")
for handler in fonttools_logger.handlers:
print(f" - {type(handler).__name__} with level {logging.getLevelName(handler.level)}")
# Check if the logger is set to propagate its messages
print(f"Propagate: {fonttools_logger.propagate}")