Anki/pylib
cav71 f4a8f7d9c7
Add support for python logging (#2969)
* adds log module

* enable logging in the app

* adds a getLogger method to AddonManager

* change log level depending on ANKIDEV

* fix undefined module variable

* - fix addons log file path
- remove a breakpoint leftover

set the addons log files under pm.addonFolder()/NNNNNN/user_files/logs/NNNNNN.log

* fix path bug

* move log closing handling into AddonManager deleteAddon/backupUserFiles methods

* logging module level import
fix undefined variable in backupUserFiles

* pretty format log records

* move MediaServer log into logging

* update CONTRIBUTORS

* documentation cleanup

* capture warnings into log messages
fix waitress verbosity

* remove record_factory function

* add get_logger method alias to getLogger in AddonManager
switch to TimedRotatingFileHandler handler
fix minor typo

* set main log level to DEBUG if ANKIDEV is not 0 (or unset)
added two new methods to AddonManager addon_get_logger/addon_toggle_log_level

* add new find_logger_output to AddonManager

* move logs under pm.base

* change log output

* update addonmanager getlogger

* Format imports

* Refactor logging set-up slightly and tweak docstring

* Remove obsolete log closing statements

As logs are no longer stored in user_files, we do not need to close their handlers

* Refactor and try to simplify log module

* Remove demo code

* Refactor and update add-on manager logging API

* Simplify writing unit tests for add-ons that use logging

Loggers are likely to be also employed in non UI code, so it seems like a good idea to decouple them from requiring a running Anki instance to work (thus freeing add-on authors from the need to mock Anki APIs in their tests).

* Fix arguments and drop obsolete inline instructions

Lets add a section on logging to the add-on docs instead

* Drop unnecessary import

* Supply logging basicConfig force option by default

Until we change the module import order and thus ensure that `log` is always evaluated before third-party dependencies have a chance to initialize the root logger, `force` is non-optional.

* Fix formatting and type errors

* Restore mediasrv type ignore comments

* Add note on prefix API stability

* Consistently use addon_from_module in new code

* Use logFolder rather than profileFolder

* Adjust method name for PEP8

* Change loggerDict access path, satisfying pylint

* Drop unused import and use lazy % formatting

* lint fix

* refactor .log_folder -> .addon_logs
store anki.log under logdir

* Fix method name (dae)

* Disable file-based logging in the backend (dae)

I have never found this useful, and it logs nothing by default, so
creating/opening the file is a waste. Removing it also ensures that
addon_logs() is solely used for add-ons.

---------

Co-authored-by: Glutanimate <5459332+glutanimate@users.noreply.github.com>
2024-02-11 16:41:50 +10:00
..
anki Add support for python logging (#2969) 2024-02-11 16:41:50 +10:00
rsbridge Drop workspace-hack in favor of workspace deps 2023-06-23 17:41:31 +10:00
tests Do not reset original_due when card stays in filtered deck (#2988) 2024-02-07 13:27:54 +10:00
tools Remove v1/v2 support from the backend (#2727) 2023-10-14 10:50:59 +10:00
.gitignore symlink generated .py/.pyi into tree to fix Python code completion 2020-12-16 11:36:42 +10:00
README.md minor doc updates 2020-12-11 22:37:12 +10:00

Anki's Python library code is in anki/.

The Rust/Python extension module is in rsbridge/; it references the library defined in ../rslib.