Anki/pylib/anki
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
..
_vendor Update Python deps 2023-03-31 14:04:05 +10:00
foreign_data Plaintext import/export (#1850) 2022-06-01 20:26:16 +10:00
importing Update licensing information (#2850) 2023-11-27 11:35:51 +10:00
scheduler Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
_backend.py Log long-running calls on the UI thread 2023-12-10 12:37:01 +10:00
_legacy.py Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
_rsbridge.pyi Rework syncing code, and replace local sync server (#2329) 2023-01-18 12:43:46 +10:00
browser.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
cards.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
collection.py Add support for python logging (#2969) 2024-02-11 16:41:50 +10:00
config.py Import submodules directly (#1662) 2022-02-13 13:40:47 +10:00
consts.py Strip out v1/v2 code 2023-09-24 14:27:40 +10:00
db.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
dbproxy.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
decks.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
errors.py Remove v1/v2 support from the backend (#2727) 2023-10-14 10:50:59 +10:00
exporting.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
find.py Add py3.9 to hooks (#1542) 2021-12-09 09:11:22 +10:00
hooks.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
httpclient.py Update Python deps 2023-03-31 14:04:05 +10:00
lang.py Fix Ukranian language name 2024-01-30 15:11:24 +10:00
latex.py Make dvipng use transparent background by default (#2036) 2022-08-31 18:49:22 +10:00
media.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
models.py Fix misleading warning when changing notetype from/to cloze (#2744) 2023-10-18 16:50:32 +10:00
notes.py Drop support for checkpoints (#2742) 2023-10-17 12:43:34 +10:00
py.typed mark anki and aqt modules as having typing info 2020-01-13 13:03:37 +10:00
rsbackend.py PEP8 for rest of pylib (#1451) 2021-10-25 14:50:13 +10:00
sound.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
stats.py Ignore rescheduled cards in old stats page (#2863) 2023-12-05 09:55:33 +10:00
statsbg.py Update licensing information (#2850) 2023-11-27 11:35:51 +10:00
stdmodels.py Add image occlusion to stock notetypes 2023-10-22 11:00:39 +10:00
storage.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
sync.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
syncserver.py Update Rust and Python deps (#2567) 2023-07-01 18:26:43 +10:00
tags.py Move custom study tag and limit gathering+saving into the backend 2022-03-10 16:23:03 +10:00
template.py Rework RenderCardOutput::question/answer 2023-06-27 00:37:41 +10:00
types.py Enable invalid-name globally in pylib (#1454) 2021-10-25 19:10:56 +10:00
utils.py Move anki.utils.html_to_text_line() to backend (#2816) 2023-11-09 09:57:23 +10:00