28namespace utility::logging
42 static bool useColor()
44 const char *noColor = std::getenv(
"NO_COLOR");
45 return noColor ==
nullptr || noColor[0] ==
'\0';
48 static const char *levelColor(LogLevel level)
51 case LogLevel::DEBUG_LEVEL:
53 case LogLevel::INFO_LEVEL:
55 case LogLevel::WARNING_LEVEL:
57 case LogLevel::ERROR_LEVEL:
64 static const char *resetColor()
74 const bool isError = record.
level == LogLevel::WARNING_LEVEL
75 || record.
level == LogLevel::ERROR_LEVEL;
76 std::ostream &stream = isError ? std::cerr : std::cout;
78 stream <<
"[" << record.
timestamp <<
"] ";
81 bool color = useColor();
83 stream << levelColor(record.
level);
87 stream << resetColor();
90 if (record.
level == LogLevel::DEBUG_LEVEL) {
91 stream <<
"[" << record.
file <<
":" << record.
line <<
" "
95 stream << record.
message <<
'\n';
98 if (policy == FlushPolicy::ALWAYS
99 || (policy == FlushPolicy::BUFFERED && isError)) {
Abstract logger interface defining stream-style logging operations.
FlushPolicy getFlushPolicy(void) const noexcept
Get the current output flush policy.
static std::string levelToString(LogLevel level)
Get string representation of log level.
StandardLogger(const std::string &name)
Constructor with logger name.
~StandardLogger(void) override
Destructor ensuring output streams are flushed.
void output(const LogRecord &record) override
Output a formatted log record to the appropriate stream.
FlushPolicy
Controls when a stream-backed logger flushes its output.
Standard output/error logger declaration.
Structured log record carrying metadata for a single log entry.
LogLevel level
Severity level.
int line
Source line number.
std::string file
Source file path.
std::string loggerName
Name of the logger that emitted the record.
std::string timestamp
Formatted timestamp string.
std::string function
Function name.
std::string message
Log message content.