struct
log_interfaceInterface for enabling library log output.
Example
A thread-safe implementation which echoes log messages on stdout and stderr:
#include <iostream> #include <mutex> #include <stim/stim.h> class iostream_logger final : public stim::log_interface { private: struct output_t { std::ostream& stream; std::mutex mx; }; output_t outputs[2] = { { std::cout }, { std::cerr } }; using lock_type = std::unique_lock<std::mutex>; public: void write(stim::log_categories category, stim::string_view, uint32_t, stim::string_view message) noexcept override { auto& out = outputs[static_cast<size_t>(category >= stim::log_categories::warning)]; const auto lock = lock_type{ out.mx }; switch (category) { case stim::log_categories::warning: out.stream << "Warning: "; break; case stim::log_categories::error: out.stream << "Error: "; break; } out.stream << message.data() << "\n"; } };
Public functions
-
void write(log_
categories category, string_ view source_file, uint32_t source_line, string_ view message) pure virtual noexcept - Writes a message to a logging output.
Function documentation
void stim:: log_interface:: write(log_ categories category,
string_ view source_file,
uint32_t source_line,
string_ view message) pure virtual noexcept
Writes a message to a logging output.
Parameters | |
---|---|
category | The message category. |
source_file | The file name of the code responsible for generating the message. |
source_line | The line number of the code responsible for generating the message. |
message | The message content. |