61 const char *lvl =
"INFO ";
70 case LogLevel::Warning:
78 std::fprintf(stderr,
"[%s] [%s] ", lvl, msg.
category.c_str());
79 if (!msg.
file.empty())
82 std::fprintf(stderr,
"%s(%d:%d): ", msg.
file.c_str(), msg.
line, msg.
column);
84 std::fprintf(stderr,
"%s: ", msg.
file.c_str());
86 std::fprintf(stderr,
"%s\n", msg.
text.c_str());
103 instance() = logger ? logger : defaultLogger();
112 static ILogger *&instance()
114 static ILogger *current = defaultLogger();
121 const std::string &file,
int line,
int col,
122 const std::string &text)
136 inline void logDebug(
const std::string &c,
const std::string &f,
int l,
int col,
const std::string &t) {
logImpl(LogLevel::Debug, c, f, l, col, t); }
137 inline void logInfo(
const std::string &c,
const std::string &f,
int l,
int col,
const std::string &t) {
logImpl(LogLevel::Info, c, f, l, col, t); }
138 inline void logWarn(
const std::string &c,
const std::string &f,
int l,
int col,
const std::string &t) {
logImpl(LogLevel::Warning, c, f, l, col, t); }
139 inline void logError(
const std::string &c,
const std::string &f,
int l,
int col,
const std::string &t) {
logImpl(LogLevel::Error, c, f, l, col, t); }
Centralized standard library includes used throughout ZenitUI.
Default ILogger that prints to stderr.
Definition Logger.hpp:57
Abstract sink for LogMessage records.
Definition Logger.hpp:49
Global registry for the active logger.
Definition Logger.hpp:92
static void set(ILogger *logger)
Install logger as the active logger.
Definition Logger.hpp:101
static ILogger & get()
Return the active logger.
Definition Logger.hpp:95
void logImpl(LogLevel level, const std::string &cat, const std::string &file, int line, int col, const std::string &text)
Internal dispatch: build a LogMessage and forward it to the active logger.
Definition Logger.hpp:120
LogLevel
Severity level attached to a LogMessage.
Definition Logger.hpp:29
A single log record passed to ILogger::log.
Definition Logger.hpp:38
std::string category
Subsystem tag, e.g. "ZMarkup".
Definition Logger.hpp:40
std::string file
Source file (may be empty).
Definition Logger.hpp:41
LogLevel level
Severity.
Definition Logger.hpp:39
int line
Source line (0 if unknown).
Definition Logger.hpp:42
std::string text
The message body.
Definition Logger.hpp:44
int column
Source column (0 if unknown).
Definition Logger.hpp:43