WeasyPrint
WeasyPrint copied to clipboard
In logs, add filename of problematic CSS
Hallo! I use weasyprint programmatically. I have followed the recommended way to log in the documentations, formatted it, and redirected it to stdout. Here is the relevant code.
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.WARNING)
logger = logging.getLogger("weasyprint")
logger.setLevel(logging.WARNING)
handler.setFormatter(formatter)
logger.addHandler(handler)
But I think its not relevant. In any case, when it logs a problematic CSS rule, it says something like this:
weasyprint - WARNING - Ignored `height: 50vh` at 243:5, invalid value.
Now, my suggestion is to make it so that the filename is mentioned in the logs. This is due to the fact that an API user can use multiple stylesheets, and knowing the filename of the problematic CSS is super helpful.
I have suggestions on how to implement this, but I literally do not know what I am doing, so yea, just some wild suggestions:
-
I suggest that this feature will work when a
filename
orurl
argument is passed toweasyprint.CSS
. such as that it looks like the following:for
filename
:easyprint - WARNING - Ignored `height: 50vh` at file [filename]:243:5, invalid value.
or for
url
:easyprint - WARNING - Ignored `height: 50vh` at url [url] 243:5, invalid value.
-
the suggestion above would not work when the passed argument is a
file_obj
orstring
, but logging the hash of the contents of thefile_obj
or thestr
would probably make it easier to find where that problematic CSS rule is. But yeah... this is probably a bad suggestion, so feel free to ignore this, or this whole issue for that matter, lol.
Thank you, have a great day!
Hi!
Now, my suggestion is to make it so that the filename is mentioned in the logs. This is due to the fact that an API user can use multiple stylesheets, and knowing the filename of the problematic CSS is super helpful.
I agree, that would be useful. We would probably have to save the information in each CSS Node in tinycss2, that would make sense.
Until then, you can set the level to INFO
. You’ll get some noise, but you’ll at least get the filenames of the related stylesheets.
Until then, you can set the level to
INFO
. You’ll get some noise, but you’ll at least get the filenames of the related stylesheets.
Ooh, thank you!