Pattern formatting (PatternFormatter):
- Token spec grammar {token:[align][width][,color]} — align <,>,^,
std::format-style width, color a name or "auto" (= the level's color).
- Custom tokens via register_token(name, fn); unknown {name} resolves
against registered renderers, then Entry::fields by key, else stays
literal — so structured fields print as {request_id:>8}.
- Color model: AnsiColor + ColorPolicy{enabled, level_colors,
token_colors} (ColorPolicy::defaults()); only PatternFormatter
colorizes (never file/JSON/logfmt). ConsoleLogger now renders its
default line through a colored PatternFormatter and exposes
set_color_policy (honors Stacktrace::Color::g_color_enabled).
Structured fields:
- Entry gains a fields vector; Logging::FieldScope (RAII, thread-local)
attaches key/values to every entry on the thread, snapshotted like
scopes. JsonLines/logfmt include them.
New file sinks (async by default):
- Detail::RollingFile factors size+max-files rotation; RotatingFileLogger
now delegates to it.
- SplitFileLogger: per-level files (<dir>/<level>.log) plus an optional
combined <dir>/all.log.
- HistoryLogger: always-on, never-level-filtered durable JSON-lines
audit trail over a rolling file.
- from_config gains split/history sinks and a log.color toggle.
22 new tests (pattern width/align/custom-token/field, color on/off + name
parsing, FieldScope nesting, split routing + combined, history JSON +
rotation, from_config split/history). 987 green; module build clean
under -Werror.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
47 lines
1011 B
C++
47 lines
1011 B
C++
#include <Void/Log/ConsoleLogger.hpp>
|
|
|
|
#ifdef VOID_HAS_STACKTRACE
|
|
#include <Void/Stacktrace/Color.hpp>
|
|
#endif
|
|
|
|
#include <iostream>
|
|
#include <ostream>
|
|
|
|
namespace Void::Logging
|
|
{
|
|
|
|
namespace
|
|
{
|
|
ColorPolicy console_default_policy()
|
|
{
|
|
ColorPolicy p = ColorPolicy::defaults();
|
|
#ifdef VOID_HAS_STACKTRACE
|
|
// Honor the global color toggle when Stacktrace is present.
|
|
p.enabled = Void::Stacktrace::Color::g_color_enabled;
|
|
#else
|
|
p.enabled = false;
|
|
#endif
|
|
return p;
|
|
}
|
|
} // namespace
|
|
|
|
ConsoleLogger::ConsoleLogger(std::ostream& out, Mode mode,
|
|
std::size_t capacity)
|
|
: Logger(mode, capacity), m_out(out)
|
|
{
|
|
m_default.set_color_policy(console_default_policy());
|
|
}
|
|
|
|
ConsoleLogger::ConsoleLogger() : ConsoleLogger(std::cerr) {}
|
|
|
|
ConsoleLogger::~ConsoleLogger() noexcept { flush(); }
|
|
|
|
void ConsoleLogger::write(const Entry& entry)
|
|
{
|
|
const Formatter& fmt = m_formatter ? *m_formatter : m_default;
|
|
m_out << fmt.format(entry) << '\n';
|
|
m_out.flush();
|
|
}
|
|
|
|
} // namespace Void::Logging
|