Skip to content

How to share the same file sink between different loggers (cateogories) #2377

Answered by tt4g
gianmarcoodorizzi asked this question in Q&A
Discussion options

You must be logged in to vote

You can get sink from logger.

// get another_logger from registry.
auto another_logger = spdlog::get("another");

// get sink by `spdlog::logger::sinks()`.
auto sinks = another_logger->sinks():
// create new_logger.
auto new_logger = std::make_shared<spdlog::logger>("new_logger", sinks.begin(), sinks.end());

// clone logger (share sinks).
auto clone_logger = another_logger->clone("clone_logger"):

Wiki: https://github.com/gabime/spdlog/wiki/4.-Sinks#adding-sinks-to-the-logger-after-creation

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@gianmarcoodorizzi
Comment options

@tt4g
Comment options

@gianmarcoodorizzi
Comment options

@tt4g
Comment options

@gianmarcoodorizzi
Comment options

Answer selected by gianmarcoodorizzi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants