Child or sub logger #2524
Unanswered
jasonbeach
asked this question in
Q&A
Replies: 1 comment 3 replies
-
How about separating the names of parent and child loggers with a separator (e.g. auto parent = spdlog::get("Foo");
std::string logger_name = parent->name() + "/" + child_name;
auto child = parent->clone(logger_name); |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
spdlog is pretty fantastic...basically my standard has become every class I write has a spdlog logger in it.
cout
is basically banned--if it's worthcout
ing then i's worth sending it to a logger with a console sink. What I'm trying to figure out is the best way to "nest" loggers--i.e. if class A has its logger, class B and C both contain class A as well as have their loggers. I have my ownLogger::get
helper function which queries the global registry for a logger and return it if it's found or creates it if it's not. So each class has:where the logger's name is set. Behind the scenes when the logger is created, the format is set so the class name (Foo in this case) is printed as part of the log statement. All loggers are going to the same file sink. Unfortunately with this arrangement it's not possible tell which statements came from the class B::A logger vs the class C::A logger.
I guess instead of setting each logger name statically, I can add a logger "namespace" argument to each class's constructor, but I was really trying to not have any logger arguments in the constructor. I guess there's not really a way to associate the loggers with each without either making them public (they're typically private) or feeding them in through a constructor or some other public function. Just wondering what other people have tried.
Beta Was this translation helpful? Give feedback.
All reactions