6.4. Project loggers#
6.4.1. Creating and using specific logger#
Python provides a built-in logging module, and we can use separate loggers for separate things.
Here is how we add a new logger to the project.
Add logger to the resources/kde-builder-logging.yaml. For example:
loggers:
resolving-dependencies:
level: INFO
...
set the level to INFO (the default level). The user could edit the level to DEBUG if he/she wants.
Note
See Changing the amount of output from kde-builder for the user documentation on changing verbosity level.
Then in the python module, import the logging module:
import logging
Then create a logger:
logger_res_deps = logging.getLogger("resolving-dependencies")
After that, you can use it, for example:
logger_res_deps.debug("Starting resolving dependencies for kcalc:")
6.4.2. Replaced perl project-wide logger with separate loggers#
kdesrc-build (predecessor of kde-builder) used one debug level for the whole project. This is very inconvenient. When you want to debug just one aspect of output, for example, the variables used when running build process, you have to see the debug logs from every other aspects, such as dependency resolution, which is very long, and you may not be interested in it.
So the original perl's project loggers were reworked.
Global log messages, that were appeared like this:
logger.error(f"r[Invalid dependency declaration: b[{dep}]]")
were assigned to specific loggers, with the corresponding severity level:
logger_res_deps.error(f"r[Invalid dependency declaration: b[{dep}]]")
Note that colorizing (the elements like r[ and ]) still can be used.
The logger.note() statements were considered as logger.warning(),
and the logger.whisper() and logger.pretend() statements were considered as logger.debug().
This is a table of log levels that was used with that conversion:
Original (perl) levels |
Python logger levels |
|---|---|
CRITICAL (50) |
|
ERROR (5) |
ERROR (40) |
WARNING (4) |
WARNING (30) |
INFO (2) |
INFO (20) |
WHISPER (1) |
DEBUG (10) |
NOTSET (0) |