Logging

Log to File and stdout

The default is to log to stdout and to _log/r8.log. There are four log levels: Info, Warning, Error and Fatal. The default output is formatted as Google GLog and can be tailed with i.e. lnav.`

#include <r8/core/log.h>
using namespace R8;
LogInfo("Hello %s", "info");
LogWarning("Hello %s", "warning");
LogError("Hello %s", "error");
LogFatal("Hello %s", "fatal");

Custom Logging

You may override both output and format to your liking by providing function pointers to the logging system.

void MyFormatFn(char* result, unsigned int size, const char* filename, unigned int line, Core::Log::Level level, const char* message) {
    // Format message as JSON.
    snprintf(result, size, "{\"message\":\"%s\"}", message);
}

void MyOutputFn(const char* formattedMessage) {
    // Write log to socket and stdout.
    write(socket, formattedMessage, strlen(formattedMessage));
    printf("%s", formattedMessage);
}
Core::Log::instance().setFormatFn(MyFormatFn);
Core::Log::instance().setOutputFn(MyOutputFn);

JSON Log Format

There is a built-in JSON format function you may use if you prefer that in favor of the default Google Logging.

Core::Log::instance().setFormatFn(Core::Log::jsonFormat);