Elektra
0.8.23
|
Import the logging library in your code:
```c #include <kdblogger.h> ```
Insert logging statements:
```c ELEKTRA_LOG("Hello, %s!", "🌎"); ```
If Elektra should display all log messages, then please follow the steps below.
Uncomment the line:
```c // #define NO_FILTER ```
in the file src/libs/elektra/log.c
.
Optional: Change the debug level in src/include/kdblogger.h
. For example, if you want to see debug messages too, then change the line
```c ELEKTRA_LOG_LEVEL = ELEKTRA_LOG_LEVEL_INFO, ```
to
```c ELEKTRA_LOG_LEVEL = ELEKTRA_LOG_LEVEL_DEBUG, ```
If you want to only log messages below a specific directory prefix, then please follow the steps below.
Search for the code:
```c #ifndef NO_FILTER // XXX Filter level … #endif ```
in the file src/libs/elektra/log.c
.
Replace the code with something like:
```c #ifndef NO_FILTER if (strncmp (file, "src/postfix/", sizeof ("src/postfix"))) goto end; #endif ```
, where src/postfix
contains all source files with logging statements that Elektra should log. For example, if you want to log everything from the yamlcpp
plugin, then use the following code.
```c #ifndef NO_FILTER if (strncmp (file, "src/plugins/yamlcpp/", sizeof ("src/plugins/yamlcpp"))) goto end; #endif ```
cmake
with the switch -DENABLE_LOGGER=ON
There are four log levels (ERROR is reserved for aborts within ELEKTRA_ASSERT
):