tlx
Loading...
Searching...
No Matches
Logger Class Reference

LOG and sLOG for development and debugging. More...

#include <core.hpp>

Public Member Functions

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

Private Attributes

std::ostringstream oss_
 collector stream
 

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;
#define LOG
Default logging method: output if the local debug variable is true.
Definition logger.hpp:24
#define sLOG
Default logging method: output if the local debug variable is true.
Definition logger.hpp:34

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.";
}
};
#define LOG1
Definition logger.hpp:28
#define LOG0
Override default output: never or always output log.
Definition logger.hpp:27

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.

Constructor & Destructor Documentation

◆ Logger()

Logger ( )

construction: add prefix if desired

Definition at line 86 of file core.cpp.

◆ ~Logger()

~Logger ( )

destructor: output a newline

Definition at line 92 of file core.cpp.

Member Function Documentation

◆ operator<<()

template<typename AnyType >
Logger & operator<< ( const AnyType & at)
inline

output any type, including io manipulators

Definition at line 90 of file core.hpp.

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: