Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.

Critique of LOG and sLOG

The macros are only for rapid module-based development. It cannot be used as an extended logging system for our network framework, where logs of network execution and communication are collected for later analysis. Something else is needed here.

Definition at line 101 of file logger.hpp.

#include <logger.hpp>

Public Member Functions

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

Static Public Member Functions

static void Output (const char *str)
 mutex synchronized output to std::cout More...
 
static void Output (const std::string &str)
 mutex synchronized output to std::cout More...
 
static void Output (const mem::safe_string &str)
 mutex synchronized output to std::cout More...
 

Private Attributes

mem::safe_ostringstream oss_
 collector stream More...
 

Constructor & Destructor Documentation

Logger ( )

Definition at line 139 of file logger.cpp.

References thrill::common::FormatNameForThisThread(), and Logger::oss_.

~Logger ( )

destructor: output a newline

Definition at line 145 of file logger.cpp.

References Logger::oss_, and Logger::Output().

Member Function Documentation

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

output any type, including io manipulators

Definition at line 119 of file logger.hpp.

References Logger::oss_.

void Output ( const char *  str)
static

mutex synchronized output to std::cout

Definition at line 118 of file logger.cpp.

References thrill::common::s_logger_mutex.

Referenced by Logger::~Logger(), and SpacingLogger::~SpacingLogger().

void Output ( const std::string &  str)
static

mutex synchronized output to std::cout

Definition at line 125 of file logger.cpp.

References thrill::common::s_logger_mutex.

void Output ( const mem::safe_string str)
static

mutex synchronized output to std::cout

Definition at line 132 of file logger.cpp.

References thrill::common::s_logger_mutex.

Member Data Documentation

collector stream

Definition at line 105 of file logger.hpp.

Referenced by Logger::Logger(), Logger::operator<<(), and Logger::~Logger().


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