Skip to content

Commit e466698

Browse files
committedMar 8, 2017
More work on LogDebugTrace pretty-printing. Still no way to turn off trace messages separately from debug.
1 parent 2b07071 commit e466698

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed
 

Diff for: ‎log.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,35 @@ void LogDebugTrace(const char* function, const char *format, ...)
267267
{
268268
lock_guard<mutex> lock(g_log_mutex);
269269

270+
//Parse out "class::function" from PRETTY_FUNCTION which includes the return type and full arg list
271+
//This normally gives us zillions of templates we dont need to see!
272+
string sfunc(function);
273+
size_t colpos = sfunc.find("::");
274+
size_t poff = sfunc.find("(", colpos);
275+
size_t coff = sfunc.rfind(" ", colpos);
276+
if( (colpos != string::npos) && (poff != string::npos) && (coff != string::npos) )
277+
{
278+
//C++ function. If we don't get here it's a C function, so use the entire function name in the log message.
279+
280+
//Get the function name
281+
size_t namelen = poff - colpos - 2;
282+
string name = sfunc.substr(colpos+2, namelen);
283+
284+
//Get the class name
285+
size_t clen = colpos - coff + 1;
286+
string cls = sfunc.substr(coff + 1, clen);
287+
288+
//Format final result
289+
sfunc = cls + "::" + name;
290+
}
291+
270292
//TODO: Check if we match a global "things we want to log" filter
271293

272294
va_list va;
273295
for(auto &sink : g_log_sinks)
274296
{
275297
//First, print the function name prefix
276-
sink->Log(Severity::DEBUG, string(function));
298+
sink->Log(Severity::DEBUG, string("[") + sfunc + "] ");
277299

278300
//then the message
279301
va_start(va, format);

0 commit comments

Comments
 (0)
Please sign in to comment.