core/logging: overhaul and many improvements -- mainly to deprecate abandoned logzero

- generally saner/cleaner logger initialization

  In particular now it doesn't override logging level specified by the user code prior to instantiating the logger.

  Also remove the `LazyLogger` hack, doesn't seem like it's necessary when the above is implemented.

- get rid of `logzero` which is archived and abandoned now, use `colorlog` for coloured logging formatter

- allow configuring log level via shell via `LOGGING_LEVEL_module_name=<level>`

  E.g. `LOGGING_LEVEL_rescuexport_dal=WARNING LOGGING_LEVEL_my_rescuetime=debug ./script.py`

- port `AddExceptionTraceback` from HPI/promnesia

- port `CollapseLogsHandler` from HPI/promnesia

  Also allow configuring from the shell, e.g. `LOGGING_COLLAPSE=<level>`

- add support for `enlighten` progress bar, so it can be shared between different projects

  See https://github.com/Rockhopper-Technologies/enlighten#readme

  This allows nice CLI progressbars, e.g. for parallel processing of different files from HPI:

    ghexport.dal[111]  29%|████████████████████████████████████████████████████████████████▏              |  29/100 [00:03<00:07, 10.03 files/s]
    rexport.dal[comments]  17%|████████████████████████████████████▋                                      | 115/682 [00:03<00:14, 39.15 files/s]
    my.instagram.android   0%|▎                                                                           |    3/2631 [00:02<34:50, 1.26 files/s]

  Currently off by default, and hidden behind an env variable (`ENLIGHTEN_ENABLE=true`)
This commit is contained in:
Dima Gerasimov 2023-06-21 16:43:20 +01:00 committed by karlicoss
parent 6aa3d4225e
commit 661714f1d9
4 changed files with 166 additions and 88 deletions

View file

@ -55,11 +55,12 @@ def main() -> None:
],
'optional': [
# todo document these?
'logzero',
'orjson', # for my.core.serialize
'pyfzf_iter', # for my.core.denylist
'cachew>=0.8.0',
'mypy', # used for config checks
'colorlog', # for colored logs
'enlighten', # for CLI progress bars
],
},
entry_points={'console_scripts': ['hpi=my.core.__main__:main']},