-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not log warnings to stdout #3135
Comments
Also, one thing I'm not sure about is if this |
Do not use sys.stdout / sys.stderr directly, since it's difficult to have common logging logic this way. Instead, replace these functions with just our log() helper. Fixes pymupdf#3135
If someone else has stumbled on this issue, note that you can circumvent it with https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout @julian-smith-artifex-com: Following up on your comment here, since I can no longer comment in the closed PR:
Cool, thanks a lot for taking this use case into consideration. I'll follow up with a new PR in the meantime.
The way that core Python libraries like requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True (this snippet actually targets If the user wants even more logging (e.g., request/response bodies), they can further enable them with a switch: http.client.HTTPConnection.debuglevel = 1 Just sharing those two ways in case they help. |
Comment out a debug statement, so that PyMuPDF does not write to stdout whenever a user initializes a Pixmap object. Refs pymupdf#3135
Comment out a debug statement, so that PyMuPDF does not write to stdout whenever a user initializes a Pixmap object. Refs pymupdf#3135
Comment out a debug statement, so that PyMuPDF does not write to stdout whenever a user initializes a Pixmap object. Refs #3135
I've just pushed a change to branch
Most of the time i'd expect only Regarding the |
That's a great development, thanks for giving us this option Julian. I'll check it out once the new PyMuPDF release is out. In the meantime, feel free to close this issue. |
Fixed in 1.24.0. |
Description of the bug
What happened?
If one installs the latest version of PyMuPDF, and they initialize a
Pixmap
object using Pythonbytes
, they will see a log message in the process' stdout:(note, this applies only to the new
fitz
module, notfitz_old
)The underlying cause is that PyMuPDF has the following logging function:
PyMuPDF/src/__init__.py
Lines 31 to 37 in 0a6f26d
This function does not employ regular Python logging, but simply writes to stdout. The stdout of a process though is not the place to write warnings, since it may interfere with binary data.
How to reproduce the bug
What I expected to happen?
Initializing a
Pixmap
object should not write anything to stdout.How to reproduce it?
fitz_new
modulePixmap
class using abytes
object for thesamples
argument (seePixmap
constructor)Or simply run:
PyMuPDF version
1.23.14
Operating system
Linux
Python version
3.11
The text was updated successfully, but these errors were encountered: