-
Notifications
You must be signed in to change notification settings - Fork 0
5. Logger registry
spdlog maintains a global (per process) registry of the created loggers.
The purpose is for loggers to be accessed easily from anywhere in the project without passing them around.
spdlog::get("logger1")->info("hello");
..
..
some other source file..
..
auto l = spdlog::get("logger1");
l->info("hello again");
Normally there is no need to register loggers as they are registered automatically for you.
To register manually created loggers(i.e. not created by the spdlog.h factory functions) use the "register_logger(std::shared_ptr<logger>)"
function:
spdlog::register_logger(some_logger);
which will register some_logger
using it's name.
spdlog will throw a sdplog::spdlog_ex
exception on attempting to register using a name that already exists in the registy
The "drop()" function can be used to remove a logger from the registry.
If no other shared_ptr pointing to the logger exists, the logger will be closed and all its resources will be freed.
spdlog::drop("logger_name");
//or remove them all
spdlog::drop_all()