Library should not call spdlog::drop_all() — breaks application loggers
Summary
The library currently calls spdlog::drop_all(), which clears all registered loggers in the global spdlog registry. This unintentionally destroys loggers created by the application using the library, leading to lost logging output and unexpected behavior.
Because drop_all() affects global state, it is not safe for use inside a library.
Problem Details
spdlog::drop_all() removes:
- the application's main logger
- loggers created by other libraries
- default spdlog loggers (e.g.,
stdout_color_mt)
Since spdlog uses a global logger registry, calling drop_all() inside a library modifies global state that the library does not own. This breaks the principle that libraries should not interfere with application‑level logging configuration.
Expected Behavior
The library should clean up only its own loggers, not the entire global registry.
Recommended Fix
Option A — Drop only the library’s loggers
Instead of calling drop_all(), explicitly drop only the loggers created by the library:
spdlog::drop("my_library_logger");
Library should not call
spdlog::drop_all()— breaks application loggersSummary
The library currently calls
spdlog::drop_all(), which clears all registered loggers in the global spdlog registry. This unintentionally destroys loggers created by the application using the library, leading to lost logging output and unexpected behavior.Because
drop_all()affects global state, it is not safe for use inside a library.Problem Details
spdlog::drop_all()removes:stdout_color_mt)Since spdlog uses a global logger registry, calling
drop_all()inside a library modifies global state that the library does not own. This breaks the principle that libraries should not interfere with application‑level logging configuration.Expected Behavior
The library should clean up only its own loggers, not the entire global registry.
Recommended Fix
Option A — Drop only the library’s loggers
Instead of calling
drop_all(), explicitly drop only the loggers created by the library: