Thrill  0.1
Logger Class Reference

Detailed Description

LOG and sLOG for development and debugging.

This is a short description of how to use LOG and sLOG for rapid development of modules with debug output, and how to keep it afterwards.

There are two classes Logger and SpacingLogger, but one does not use these directly.

Instead there are the macros: LOG and sLOG that can be used as such:

LOG << "This will be printed with a newline";
sLOG << "Print variables a" << a << "b" << b << "c" << c;

There macros only print the lines if the boolean variable debug is true. This variable is searched for in the scope of the LOG, which means it can be set or overridden in the function scope, the class scope, from inherited classes, or even the global scope.

class MyClass
{
static constexpr bool debug = true;
void func1()
{
LOG << "Hello World";
LOG0 << "This is temporarily disabled.";
}
void func2()
{
static constexpr bool debug = false;
LOG << "This is not printed any more.";
LOG1 << "But this is forced.";
}
};

There are two variation of LOG and sLOG : append 0 or 1 for temporarily disabled or enabled debug lines. These macros are then LOG0, LOG1, sLOG0, and sLOG1. The suffix overrides the debug variable's setting.

After a module works as intended, one can just set debug = false, and all debug output will disappear and be optimized out.

Definition at line 78 of file core.hpp.

#include <core.hpp>

Public Member Functions

 Logger ()
 construction: add prefix if desired More...
 
 ~Logger ()
 destructor: output a newline More...
 
template<typename AnyType >
Loggeroperator<< (const AnyType &at)
 output any type, including io manipulators More...
 

Private Attributes

std::ostringstream oss_
 collector stream More...
 

Constructor & Destructor Documentation

◆ Logger()

Logger ( )

construction: add prefix if desired

Definition at line 86 of file core.cpp.

References LoggerPrefixHook::add_log_prefix(), and tlx::s_logger_prefix_hook.

◆ ~Logger()

~Logger ( )

destructor: output a newline

Definition at line 92 of file core.cpp.

Referenced by Logger::operator<<().

Member Function Documentation

◆ operator<<()

Logger& operator<< ( const AnyType &  at)
inline

output any type, including io manipulators

Definition at line 90 of file core.hpp.

References Logger::~Logger().

Member Data Documentation

◆ oss_

std::ostringstream oss_
private

collector stream

Definition at line 82 of file core.hpp.


The documentation for this class was generated from the following files: