Author Topic: Standard logging to replace plethora of if(SystemFlags::getSystemSetings...)  (Read 512 times)

ssteinerX

  • Guest
While reading through the MG code, I've seen a huge number of these type things:

if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());

Sorry for the crappy formatting, but it's all just like that on one line, stretching out to the 295th character position.

A standard logging system would reduce this to one line (paraphrased, I haven't coded in C++ in probably 15 years):

logger.network("This is the message");

Where all the other __FILE__, __FUNCTION__, and __LINE__ stuff is automatically handled by the logger.

If the network logger's not enabled, the message falls on the floor and you have the overhead of a function call.  If it is, the message can be routed to anywhere.

The method used in this codebase just seems so old-school, and not in a good way...

Here's one implementation:

http://log4cpp.sourceforge.net/

ssteinerX


 

anything