Jump to content

Log messages filter and debug log level


photo

Recommended Posts

Hi,

 

One interesting feature (and I think not so hard to develop) is to include a minimum log message level.

It can be defined at unigine.cfg file as follows:

<item name="log_level" type="string">"warning"</item>

 

All the messages under this level mustn't be included in log.html file.

With this feature and the inclusion of "debug" log level (log.debug) you can keep messages in critical parts of your code and easily activate/deactivate them.

 

Currently I'm using #define macros to achieve this, but it's not the best solution.

 

log4cxx uses this feature, but in our case, it's much more simple.

 

Cheers,

Iván.

  • Like 1
Link to comment

The cost is compare two integers for each log call. The benefits are:

  • Quickly restore messages to fix bugs or benchmark code.
  • Save time spent formating and writting undesired messages (some of them lost in code)

In my opinion it's a low penalty.

 

Another idea is to have log level comparision in debug builds (as breakpoint function) using macros.

//for each log function
/*
*/
void Log::message(string msg) {
#ifdef DEBUG
 if(MESSAGE_LEVEL < current_log_level)
return;
#endif /* DEBUG */
 // ...
}

Link to comment

I don't think the integer compare would be an issue. Can remember some profiling where the actual message text formatting took 10x the time required for log message invocation itself. I would doubt that unigine script compiler can optimize this dead code away when not needed due to log level setting.

Link to comment
  • 3 weeks later...

There are already warnings, errors and messages, so if you need to implement a minimum message level, why not write custom wrapper functions in script?

Link to comment
×
×
  • Create New...