1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.


use macros in include/utils/logger.h
Don't use the Logger class directly unless there is a good reason to do so.

// *** including
#include <utils/logger.h>

// creating
// get a logger, this will create a logger named MAIN with min loglevel INFO, DEBUG messages won't displayed
Logger * log_main = Logger::getInstance("MAIN");

// get a logger, this will create a logger named MAIN with min loglevel DEBUG,  all messages displayed
Logger * log_main = Logger::getInstance("MAIN", Logger::DEBUG);

// using
// basic
Debug( log_main, "hello folks!");
Info( log_main, "hello again!");
Warning( log_main, "something is crazy");
Error( log_main, "oh to crazy, aborting");

// quick logging, when only one message exists and want no typing overhead - or usage in static functions
Info( Logger::getInstance("LedDevice"), "Leddevice %s started", "PublicStreetLighting");

// a bit mor complex - with printf like format
Info( log_main, "hello %s, you have %d messages", "Dax", 25);

// conditional messages
WarningIf( (value>threshold), log_main, "Alert, your value is greater then %d", threshold );

An Example from migrating from console out (std::cout) to logger usage is seen in following github commit:


(the effect files)

The format string

set a placeholder (%s %d %f) in the message where you want to add a specific variable.

Info( log_main, "hello %s, you have %d messages", "Dax", 25);

The amount of "%" mus match with following arguments.

The Placeholders
%s for strings (this are cstrings, when having std::string use myStdString.c_str() to convert)
%d for integer numbers
%f for float numbers

more placeholders possible, see http://www.cplusplus.com/reference/cstdio/printf/

Log Level

Debug - used when message is more or less for the developer or for trouble shooting

Info - used for not absolutly developer stuff messages for what's going on

- warn if something is not as it should be, but didn't harm

Error - used an error occurs

This page has been seen 2,847 times.