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.

Templates#

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

The template identifies the severity

  • log::info(...)

  • log::warn(...)

  • log::error(...)

  • log::critical(...)

In particular, a critical log message will

  • try to flush log buffers,

  • write a backtrace to stderr,

  • abort the running process and

  • maybe create a core dump.

There is one more facility

  • log::debug(...)

which will only be included when NDEBUG has not been defined.

Formatting#

The log message itself is being generated by fmt.

Note

We only support std::string_view for the format string. The reason is that generic strings, and char const * in particular, may imply run-time checking of string length.

Some examples

log::info("Trivial"sv);
log::warn("Latency {} exceeds the threshold of {}"sv, latency, threshold);
log::error(R"(Invalid key="{}")"sv, key);
log::critical("Unexpected"sv);

Verbosity#

Verbosity can be controlled by setting the ROQ_v environment variable

Note

Default verbosity level is 0 (zero).

Some examples

log::info<0>("Same as log::info"sv);
log::info<1>("Will only log when ROQ_v >= 1"sv);
log::info<2>("Will only log when ROQ_v >= 2"sv);

Service#

struct Service#

Convenience class to wrap roq::Logger, absl::flags, etc.

Public Functions

int run()#

The main function.

struct Info#

Tool#

struct Tool#

Convenience class to wrap roq::Logger, absl::flags, etc.

Public Functions

int run()#

The main function.

struct Info#

Logging#

template<std::size_t level = 0>
struct info#
template<std::size_t level = 0>
struct warn#
template<std::size_t level = 0>
struct error#
template<typename ...Args>
constexpr void roq::log::critical(format_str<Args...> const &fmt, Args&&... args)#
template<typename ...Args>
constexpr void roq::log::fatal(format_str<Args...> const &fmt, Args&&... args)#
template<std::size_t level = 0>
struct debug#
template<std::size_t level = 0>
struct system_error#

Print#

struct print#