logog
logger optimized for games
Deferring logging output

Writing debug output can take a lot of time on most platforms. Especially in programs that produce copious debug output, logging can slow a program's operation considerably.

To get around this behavior, use the LogBuffer class. To Create a LogBuffer, you provide a pointer to the ultimate Target you want to write to, such as a Cerr or a LogFile, as well as the size of the LogBuffer. Logging then occurs solely to the LogBuffer, and no output is written to the Target until the LogBuffer is destroyed, or the LogBuffer::Dump() method is called.

In normal operation, the LogBuffer object will flush its contents to the underlying target when it gets full. However, if you wish, you can force the LogBuffer to flush its contents by calling the LogBuffer::Dump() method upon it. Make sure to set the bEnableOutputBuffering parameter to false when creating the LogFile, so that the underlying C library does not itself buffer the output when writing.

{
/* Avoid output buffering on the log file by providing false to the
* bEnableOutputBuffering parameter.
*/
LogFile logFile("log.txt", false);
LogBuffer logBuffer(&logFile);
logBuffer.SetNullTerminatesStrings(false);
logFile.UnsubscribeToMultiple(AllFilters());
Formatter *pFormatter = &GetDefaultFormatter();
pFormatter->SetShowTimeOfDay(true);
ERR(_LG("This is an error"));
DBUG(_LG("This is debugging information"));
/* At this point the LogBuffer will flush to the LogFile, and the
* LogFile will immediately flush its output to the file system.
*/
logBuffer.Dump();
WARN(_LG("a WARNING MESSAGE WITH number %.3f"), 0.43543);
/* The LogBuffer will immediately be flushed again and all log
* information written to the file.
*/
logBuffer.Dump();
}