WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

ISSUE-1585 | Surface fontTools logs for easier investigation

Open kdipippo opened this issue 1 year ago • 1 comments

Work-in-progress.

Taking the feedback from the following 2 issues into this PR:

  • https://github.com/Kozea/WeasyPrint/issues/1585
  • https://github.com/fonttools/fonttools/issues/3538

kdipippo avatar May 28 '24 17:05 kdipippo

After thinking about the best way to solve this issue, here’s what seems to be the best solution for me.

The code needed to capture logs is already in WeasyPrint: it’s used for tests, to check that we get no warning or the intended warning messages, depending on the test.

https://github.com/Kozea/WeasyPrint/blob/6e93e95354dc968180b09986fb23c3e35c8cbfe1/tests/testing_utils.py#L73-L100

What we could do is:

  • Move CallbackHandler and capture_logs to logger.py.
  • Add a parameter to capture_logs to define the logger we want to capture. Its default value would be 'weasyprint' to keep the current default behaviour.
  • Use with capture_logs('fontTools') as logs: around the call to subsetter.subset() and display the logs thanks to LOGGER.warning(), just as you did in your PR.

What do you think of this solution?

As the code has changed a bit in main, you should probably create a new branch from main, create a new commit and push force to your branch.

liZe avatar Jun 09 '24 09:06 liZe

I’ve fixed the problem in 61852c4. Thanks a lot for your investigation and for your proposal. 💜

liZe avatar Jul 03 '24 19:07 liZe