}
ensure_indent_level(PerThread, Depth);
PerThread->scope_tracker_list.push_back(this);
- {
- std::ostringstream ostr;
- if (Location.FunctionName.empty())
- {
- ostr << "<unknown> (global scope?)";
- }
- else
- {
- ostr << shorten_stl_types(Location.FunctionName);
- if (FuncDepth>0)
- {
- ostr << "#" << FuncDepth+1;
- }
- }
- Tag= ostr.str();
- }
+
// spit a message
if (Logger::has_log_level(Logger::LogLevel::Debug))
{
- GlobalLogger.debug() << PerThread->indents[Depth] << "ENTER " << Tag;
+ GlobalLogger.debug() << PerThread->indents[Depth] << "ENTER " << get_tag();
}
} // eo ScopeTrcaker::ScopeTracker(const SourceLocation&)
/**
+ * @brief create Tag if empty; return reference to it
+ *
+ * Moved this from constructor into own function to avoid creating Tag if it is
+ * not required (i.e. log level is not DEBUG) but still create it only once and
+ * ensure it is available if log level changes inside tracked function
+ */
+std::string& ScopeTracker::get_tag()
+{
+ if (Tag.empty())
+ {
+ if (Location.FunctionName.empty())
+ {
+ Tag = "<unknown> (global scope?)";
+ }
+ else
+ {
+ std::ostringstream ostr;
+ ostr << shorten_stl_types(Location.FunctionName);
+ if (FuncDepth>0)
+ {
+ ostr << "#" << FuncDepth+1;
+ }
+ Tag= ostr.str();
+ }
+ }
+ return Tag;
+}
+
+
+/**
* @brief destructor. emits a LEAVE message.
*
*
// spit a message
if (Logger::has_log_level(Logger::LogLevel::Debug))
{
- GlobalLogger.debug() << PerThread->indents[Depth] << "LEAVE " << Tag;
+ GlobalLogger.debug() << PerThread->indents[Depth] << "LEAVE " << get_tag();
}
if (PerThread->scope_tracker_list.empty())
{