Skip to content

Architecture Debugging

Paul Heinen edited this page Jul 13, 2016 · 4 revisions

Debugging

The heart of our debugging system is a global logger built around Boost.Log v2. The whole logging system is contained in the files debugging.h and debug.cpp, and by simply including the debugging.h file, you automatically have access to the logger.

There are multiple logging levels, and they can be used by simply saying: LOG_<LOG_LEVEL> << "Some text " << some_variable << " more text"; When called, a log message displaying the time it was logged, the time it was logged since the start of the program, the log level, and if BOOST_LOG_FUNCTION() is included in the function, a trace of where the log was called from will be included as well. The log message will be written to console as well as to a file containing other log messages with the same severity level in NAO-engine/logs.

A minimum threshold for log severity can be set in the debugging.h file with the macro #define SEVERITY_THRESHOLD logging::trivial::<log_level>. The options for log severity thresholds are as follows:

    1. trace
    1. info
    1. debug
    1. warning
    1. error
    1. fatal

An example of using the logging system with a trace can be seen in the following example:

void foo(){
    BOOST_LOG_FUNCTION();
    LOG_DEBUG << "A different kind of message called from a function.";
}
void bar(){
    LOG_DEBUG << "Without function call trace.";
}
int main(){
    BOOST_LOG_FUNCTION();
    LOG_INFO << "A simple log message called from main.";
    foo();
    bar();
    return 0;
}

We then set the severity level in debugging.h: #define SEVERITY_THRESHOLD logging::trivial::debug

The output will look something like this:

1 [12.07.2016 18:53:28.063066] [info] [00:00:00.000479] [int main()] A simple log message called from main.
2 [12.07.2016 18:53:28.063775] [debug] [00:00:00.001186] [void foo()<-int main()] A different kind of message called from a function.
3 [12.07.2016 18:53:28.064052] [debug] [00:00:00.001464] [int main()] Without function call trace.