AIToolbox
A library that offers tools for AI problem solving.
How Logging Works

Since AIToolbox is a library, it leaves the choice of how to log to you. You can use any framework, library or C++ iostream facilities you want.

Enabling Logging in the Library

In order to enable logging the library MUST be compiled with the flag AI_LOGGING_ENABLED set to 1 (You can do this via CMake). If it's not, no logging will be produced by the pre-compiled parts of the library.

In addition, you need to set the AI_LOGGING_ENABLED macro to 1 before including any AIToolbox header files in your project too, or logging in header-only classes will not work.

This has been done in order to obtain the best possible performance when logging is disabled.

Setting the Logging Function

In order to log you need to overwrite the AIToolbox::AILogger function pointer. This is a pointer to a function with signature:

void(int severity, const char * message);

So for example, in your code you could define:

void myLoggerFunction(int severity, const char * message) {
    std::cout << '[' << severity << "] " << message << '\n';
}

And then, at the beginning of your main function:

AIToolbox::AILogger = myLoggerFunction;

And this would start logging automatically with no filtering. Remember to include the logging header!

#include <AIToolbox/Logging.hpp>

Priorities and Log Information

AIToolbox defines 4 different severity levels:

  • AI_SEVERITY_DEBUG (0),
  • AI_SEVERITY_INFO (1),
  • AI_SEVERITY_WARNING (2),
  • AI_SEVERITY_ERROR (3)

These values represent how the AIToolbox library splits log severities.

Logs do not contain newlines. Logs do not contain file/line information.

The max length of logs is capped at compile time. The variable logBuffer is a char array which temporarily contains the message before it is passed to your function. By default, the length of this array is 500. If you need longer logs, feel free to change the length of the array and recompile.