1.3.1. SDK Logging
The Proximie SDK provides diagnostic logging support, with the option to set the output/detail level with a severity setting.
By default, the SDK logs output to standard output and error streams, depending
on the severity of the message (namely warnings and errors to error output,
and the informational levels to standard output).
See LogSeverity
for supported log levels.
Logging delegates
The Proximie SDK allows the application handle logging by providing a logging
delegate. This delegate needs to be a class derived from the abstract class
PxLogger::ILoggerDelegate
,
which implements a simple interface to provide logging for the application.
A minimal logger implementation might look like this:
using namespace Proximie::PxCore;
class MinimalLogger : public PxLogger::ILoggerDelegate
{
public:
// Implement the actual logging suitable for your application
void handleLog(PxLogger::LogSeverity level, const char* message,
const PxLogger::LogMeta& data) override;
};
void MinimalLogger::handleLog(PxLogger::LogSeverity level, const char* message,
const PxLogger::LogMeta& data) {
auto& out = level >= PxLogger::LogSeverity::ERROR ? std::cerr : std::cout;
out << PxLogger::timestamp(data.timestamp)
<< " [" << PxLogger::severityLabel(level) << "] "
<< PxLogger::escapeFormat(message) << std::endl;
}
Note the helper functions like
PxLogger::severityLabel
,
which can be used to help format logging output. To set the delegate, you need to
create your logger as a std::shared_ptr
and pass it to the SDK logger:
auto logger = std::make_shared<MinimalLogger>();
PxLogger::get()->setDelegate(logger);
Log levels
The default SDK log level is set to LogSeverity::Info
.
PxLogger
also provides the ability to set the
logging severity using severityLevel()
.
You can optionally provide the log level when setting the delegate:
PxLogger::get()->setDelegate(logger, PxLogger::LogSeverity::ERROR);
Also to set (or reset) to the standard output logger:
PxLogger::get()->useStdOutputDelegate(PxLogger::LogSeverity::DEBUG);