This PR creates a logging/tracing library for Trieste to use. This can then be used by downstream projects such as rego-cpp and verona. The intent is to reduce the cost of checking whether log should be generated.
There is a pure C++ approach to using the library
trieste::logging::Info() << "Hello " << 5;
that will output a log message if the Info level should be printed. The messages are output on destruction of the Log object, so that there is no tearing in a concurrent setting.
The log object can also be a local variable to allow more complex messages to be constructed.
trieste::logging::Info out;
out << "Hello" << trieste::logging::Indent;
for (int i = 0; i < 10 ; i++)
out << "i = " << i << std::endl;
out << trieste::logging::Undent;
out << "Goodbye.";
which will print the following at the end of out's scope:
Hello
i = 0
i = 1
i = 2
Goodbye.
Here we use the Indent and Undent line terminators that alter the indentation level of the following lines.
The implementation tries very hard to force the compiler to move the logging off the fast path. For example:
size_t fib(size_t i)
{
if (i < 2)
{
return i;
}
logging::Info() << "fib(" << i << ") = ? " << std::endl;
auto result = fib(i - 1) + fib(i - 2);
logging::Info() << "fib(" << i << ") = " << result << std::endl;
return result;
}
This PR creates a logging/tracing library for Trieste to use. This can then be used by downstream projects such as rego-cpp and verona. The intent is to reduce the cost of checking whether log should be generated.
There is a pure C++ approach to using the library
that will output a log message if the
Info
level should be printed. The messages are output on destruction of theLog
object, so that there is no tearing in a concurrent setting.The log object can also be a local variable to allow more complex messages to be constructed.
which will print the following at the end of
out
's scope:Here we use the
Indent
andUndent
line terminators that alter the indentation level of the following lines.The implementation tries very hard to force the compiler to move the logging off the fast path. For example:
generates
There is additionally a macro that can be enables
LOG
with definingTRIESTE_EXPOSE_LOG_MACRO
. This uses macro tricks such thatwill only evaluated
fib(23)
if theInfo
level should be printed. This is not the case for the pure C++ version: