Bugzilla – Bug 1552
Storing log name inside LogComponent class (NS_LOG) as std::string
Last modified: 2013-10-28 17:51:01 EDT
I'm using a template-based model implementations, where in order to make logging work I need to use a little bit more complex logging initialization. In particular, I have a static method in a class that constructs name on the fly, based on names of parent classes. (You can check https://github.com/NDN-Routing/ndnSIM/blob/master/model/fw/per-fib-limits.h for my a slightly crazy example of that.)
Currently, when LogComponent is initialized, it stores a supplied pointer const char* to a member variable, without actually copying the string. In all current cases this is fine (as it points to a static data), but in my case---dynamic string creationg---that caused a disaster.
So, my suggestion is to just change an internally stored type in LogComponent to std::string, which involves two small changes:
change in log.h
@@ -394,7 +394,7 @@ public:
std::map<enum LogLevel, std::string> LevelLabels() const;
- char const *m_name;
+ std::string m_name;
change in log.cc
@@ -261,7 +261,7 @@ LogComponent::Disable (enum LogLevel level)
char const *
LogComponent::Name (void) const
- return m_name;
+ return m_name.c_str ();
Do you think it is a reasonable change?
(In reply to comment #0)
> Do you think it is a reasonable change?
it looks reasonable. I can't find out what could go wrong here.
Almost that simple.