6.7. Project loggers#
6.7.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 data/kde-builder-logging.yaml
. For example:
loggers:
resolving-dependencies:
level: INFO
...
set the level to INFO
(the default level used in kdesrc-build). 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 kbLogger
module:
from Debug import kbLogger
Then create a logger:
logger_res_deps = kbLogger.getLogger("resolving-dependencies")
After that, you can use it as normal logging.Logger
logger, for example:
logger_res_deps.debug("Starting resolving dependencies for kcalc:")
6.7.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:
Debug().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 Debug().note()
statements were considered as Debug().warning()
,
and the Debug().whisper()
statements were considered as Debug().debug()
.
The pretend()
method was also ported and can still be used.
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) |