Replace print() logging in pylib with Python logging#4666
Open
davidsauerwein wants to merge 1 commit intoankitects:mainfrom
Open
Replace print() logging in pylib with Python logging#4666davidsauerwein wants to merge 1 commit intoankitects:mainfrom
davidsauerwein wants to merge 1 commit intoankitects:mainfrom
Conversation
Use Python logging facilities instead of printing directly to stdout with print(). This prevents library consumers from being spammed with unwanted debug logs and stack traces. Closes ankitects#4665
Documentation build overview
Show files changed (3 files in total): 📝 3 modified | ➕ 0 added | ➖ 0 deleted
|
Collaborator
|
Can we keep print() for deprecation warnings? With the default INFO level set by setup_logging(), add-on authors/users won't see the messages unless the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use Python logging facilities instead of printing directly to stdout with print(). This prevents library consumers from being spammed with unwanted debug logs and stack traces.
Closes #4665
My approach to the log levels is
warningfor any deprecation warning anddebugfor the "blocked main thread" messages.The pylib is used in the qt parts of the anki code. To the best of my understanding, logging is already correctly set up there and no adjustments are needed.
The issue I created for this has a reproducer. With this change applied, the messages are gone when configuring the anki logger accordingly.
setting the anki logger back to
DEBUGmakes the message appear again. Note that the format is only slightly different then previously.DEBUG:anki._backend:blocked main thread for 309ms Stack (most recent call last): File "/home/david/coding_stuff/anki/repro.py", line 8, in <module> auth = col.sync_login( File "/home/david/coding_stuff/anki/.venv/lib/python3.14/site-packages/anki/collection.py", line 1141, in sync_login return self._backend.sync_login( File "/home/david/coding_stuff/anki/.venv/lib/python3.14/site-packages/anki/_backend_generated.py", line 83, in sync_login raw_bytes = self._run_command(1, 3, message.SerializeToString()) File "/home/david/coding_stuff/anki/.venv/lib/python3.14/site-packages/anki/_backend.py", line 168, in _run_command logger.debug(