roq-logging

Output

Always using stdout and stderr.

Synchronicity

Logging is synchronous if the process has an attached terminal. This is normally what you want if you’re launching the program from the command-line.

Loggig is asynchronous if the process has no attached terminal. This benefits the predictability of latency of the running process because it can offload the writing of the message to a secondary thread.

Macros

Logging capabilities are accessed through macros. This is done to capture filename and line number at the point where the log message is being generated.

Logging must identify the severity

  • INFO

  • WARNING

  • ERROR

  • FATAL

In particular, a fatal log message will

  • try to flush log buffers,

  • write a backtrace to stderr,

  • abort the running process and

  • maybe create a core dump.

The log message itself is being generated by fmt.

Some examples

LOG(INFO)("Trivial");
LOG(WARNING)("Latency {} exceeds the threshold of {}", latency, threshold);
LOG(ERROR)(R"(Invalid key="{}")", key);
LOG(FATAL)("Unexpected");

Verbosity can be controlled by setting the ROQ_v environment variable (the default value is 0 (zero)).

Some examples

VLOG(0)("Same as INFO");
VLOG(1)("Will log when ROQ_v >= 1");
VLOG(2)("Will log when ROQ_v >= 2");

Debug logging will only be active for debug builds, i.e. when NDEBUG has not been defined.

Some examples

DLOG(INFO)("Will log for debug builds, only");
DLOG(WARNING)("Will also only log for debug builds");

Conditional logging is easy, just append _IF and add an expression.

Some examples

LOG_IF(INFO, success)("Success!");
VLOG_IF(1, value > 3)("Value is larger than three");

Application

Warning

doxygenclass: Cannot find class “roq::Application” in doxygen xml output for project “roq-logging” from directory: /opt/buildagent/temp/buildTmp/share/doc/roq-logging/xml

Logger

struct roq::Logger

Interface to manage the lifetime of the single static logger.

Public Static Functions

void initialize(const std::string_view &arg0, const std::string_view &pattern = std::string_view(), bool stacktrace = true)

Initialize the logger.

void shutdown()

Shutdown the logger.