Univention Bugzilla – Bug 49037
use best practice python logging
Last modified: 2019-11-18 17:11:41 CET
A lot of UCS@school lib and import modules create handlers when they should only be creating loggers. Also: loggers should not be created at module level, because they might be imported and created before a logger further up in the hierarchy is configured using logging.config.fileConfig() or logging.config.dictConfig(). They disable previous loggers by default.
The ucsschool.libs and the imports get_logger() functions have been deprecated. Please use everywhere just: --- logger = logging.getLogger(__name__) --- Avoid creating the Logger instance on the module level. To add a file handler use: ucsschool.lib.models.utils.get_file_handler() To add a stream (console) handler use: ucsschool.lib.models.utils.get_stream_handler() All console output is now colorized. The default colors from colorlog (https://github.com/borntyping/python-colorlog) are used atm. We should discuss them as a team. python-colorlog is currently in 4.3-unmaintained. I have added it to the ucs_4.4-0-ucs-school-4.4 scope. [dtroeder/improve_logging] 4f09b47a6 Bug #49037: provide handlers separately from loggers, colorize console output [dtroeder/improve_logging] 202254c52 Bug #49037: provide logger to all UCS@school lib objects [dtroeder/improve_logging] abbe50ff7 Bug #49037: use UCSSchoolHelperAbstractClass logger [dtroeder/improve_logging] 39e16057c Bug #49037: use explicit relative imports for modules of own package or direct parent/child package [dtroeder/improve_logging] 7007a5569 Bug #49037: create a logger per module, use provided handlers, don't create loggers at module level Please reopen, when starting QA (missing merge, changelogs and package builds).
Uncluttered utils.py by moving the logging configuration into a config file. (Removed unnecessary symbols from shell.py.) [dtroeder/improve_logging 5c3e66c49] Bug #49037: move constants to config file
looks good so far. Please build and add advisory for final QA
[4.4] 4e0e3b57d Bug #49037: Merge branch 'dtroeder/improve_logging' into 4.4 [4.4] 87cb71117 Bug #49037: remove now superfluous custom ColorFormatter [4.4] 33d21fb36 Bug #49037: changelogs [4.4] f46186577 Bug #49037: update dependencies [4.4] 2802b5dc0 Bug #49037: advisories ucs-school-lib (12.1.0-15) ucs-school-import (17.0.5-7) ucs-test-ucsschool (6.0.0-32)
Reintroduce a switch like ColorFormatter used, to not have control symbols for cmdline colors in logfiles like jenkins runs.
[4.4] df5f9100c Bug #49037: don't colorize output that's redirected away from a terminal [4.4] f0fa0e1f0 Bug #49037: adjust handlers loglevel after reading configuration [4.4] ba55ab487 Bug #49037: adjust test to pyhook test and logging [4.4] e6c07e00b Bug #49037: advisory updates ucs-school-lib (12.1.0-16) ucs-school-import (17.0.5-8) ucs-test-ucsschool (6.0.0-33)
Changelog&Advisory: OK Package installs: OK Jenkins tests: OK Changes effective: OK
* The INFO level is now white, it was grey/light_white like DEBUG. * Color configuration is stored in the same YAML file as the format configuration. * The handler that prevents colorizing output in case of a missing TTY, was preventing colorization if run by ucs-test. Users of ImportTestbase._get_logger() now get colored output anyway. * The get_stream_handler() function now allows to set a custom Formatter class. * The get_stream_handler() function now allows to force colorization by setting the environment variable UCSSCHOOL_FORCE_COLOR_TERM. [4.4] 0cd121db3 Bug #49037: allow to force colorized output, load colors from configuration file [4.4] e6f1270bb Bug #49037: prevent adding 2nd stream handler [4.4] 73067ee51 Bug #49037: force colorized output if run interactively by ucs-test but not when run from jenkins [4.4] b0cf3c96f Bug #49037: advisory updates
[4.4] 784d62a9b Bug #49037: simplify TTY testing [4.4] d52e9e583 Bug #49037: make get_ucsschool_logger() accessable for all tests [4.4] dc961311f Bug #49037: advisory update
bChangelog&Advisory: OK Package installs: OK Jenkins tests: OK Changes effective: OK
UCS@school 4.4 v2 has been released. https://docs.software-univention.de/changelog-ucsschool-4.4v2-de.html If this error occurs again, please clone this bug.