How to disable a single sink? #2843
-
I have a default logger with multiple sinks: For a specific part/path of the application I need to dump output (JSON) to the console. For that path I need to disable the I use the default logger on startup and add the rest of the sinks.
I want to clone the default since I still need to use the other sinks without having to recreate any of them. Is this possible or should I rethink my flow? PS: The commands are dynamic. At the time where the default logger is set up, the application does not know that |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
If you just want to implement pseudo code, it looks like this: for (auto sink : logger->sinks()) {
std::shared_ptr<SINK_T> stdout_sink = std::dynamic_pointer_cast<SINK_T>(sink);
if (stdout_sink) {
stdout_sink->set_level(spdlog::level::off);
}
} However, the logging level must be restored. |
Beta Was this translation helpful? Give feedback.
-
I decided to go with the following, mostly for the reason that I don't like dynamic cast:
But I will consider reworking it to remove the sink instead. |
Beta Was this translation helpful? Give feedback.
Perhaps just remove those sinks instead of setting the level. This way you don't need to restore the levels (and performance is better since the new logger wont store those sinks at all).