♻ ️ add `logs` configuration settings and replace logging system by `spdlog`
Adds configuration keys to tweak the logger behavior:
{
"logs": {
"filepath": "/path/to/log_file",
"log_level": "warn",
"max_files": 3,
"max_size": 100
}
}
There is now a simple way to log stuff and an interface to retrieve a registered logger. These can be retrieved from anywhere in the program using spdlog::get(logger_name)
that returns a shared pointer to the logger.
auto logger = spdlog::get("switcher");
logger->info("Cocorico!");
2021-11-25 12:34:56.808|default|4264f281-9e77-41d0-aee9-b435954c44de|126238|126238|info: Cocorico!|:
Note that this would not show the
basename
of the source file, nor theline number
where the logger function was called.
To show basename
and line number
in logs, use this instead:
auto logger = spdlog::get("switcher");
LOGGER_INFO(logger, "Cocorico! {} {:d}", "Pain au Chocolat", 42);
2021-11-25 12:34:56.808|default|4264f281-9e77-41d0-aee9-b435954c44de|126238|126238|info: Cocorico! Pain au Chocolat 42|file.cpp:84
The logger first uses a console sink
as its main output until the logs
settings can be checked, then it takes a file sink
in addition to the console sink
. This integration respects the previous one as much as possible to limit procedural changes in developers workflows. The previous logging system has been completely removed from the project and with it the many ways to use it.
Each instance of Switcher use a unique global logger but has its own sinks
identified by the instance name
and uuid
.
Here's a snapshot of what logging looks like now:
Read documentation for the key in Configuration for more