33 [[nodiscard]]
const std::string&
getName() const noexcept {
return _name; }
37 void setLevel(
LogLevel level)
noexcept { _level.store(level, std::memory_order_relaxed); }
38 [[nodiscard]]
LogLevel getLevel() const noexcept {
return _level.load(std::memory_order_relaxed); }
44 void flushOn(
LogLevel level)
noexcept { _flushLevel.store(level, std::memory_order_relaxed); }
48 void addSink(std::shared_ptr<ISink> sink);
52 bool removeSink(
const std::shared_ptr<ISink>& sink)
noexcept;
54 [[nodiscard]] std::
size_t sinkCount() const noexcept;
58 template <class... Args>
62 vlog(level, source, _name, format.get(), std::make_format_args(args...));
67 void vlog(
LogLevel level,
const SourceLocation& source, std::string_view category, std::string_view format, std::format_args args)
noexcept;
70 template <
class... Args>
void trace(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Trace, {}, format, std::forward<Args>(args)...); }
71 template <
class... Args>
void debug(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Debug, {}, format, std::forward<Args>(args)...); }
72 template <
class... Args>
void info(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Info, {}, format, std::forward<Args>(args)...); }
73 template <
class... Args>
void warn(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Warn, {}, format, std::forward<Args>(args)...); }
74 template <
class... Args>
void error(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Error, {}, format, std::forward<Args>(args)...); }
75 template <
class... Args>
void fatal(std::format_string<Args...> format, Args&&... args)
noexcept {
log(
LogLevel::Fatal, {}, format, std::forward<Args>(args)...); }
94 void dispatch(const
LogMessage& message) noexcept;
99 std::unique_ptr<SinkList> _sinks;
Named logger that formats messages and sends them to its sinks; thread-safe.
Definition Logger.hpp:24
void fatal(std::string_view message) noexcept
Definition Logger.hpp:86
void trace(std::string_view message) noexcept
Definition Logger.hpp:81
void setLevel(LogLevel level) noexcept
Minimum level to log; LogLevel::Off disables the logger.
Definition Logger.hpp:37
std::size_t sinkCount() const noexcept
void log(LogLevel level, const SourceLocation &source, std::format_string< Args... > format, Args &&... args) noexcept
Logs a message at level with its source location.
Definition Logger.hpp:59
void warn(std::string_view message) noexcept
Definition Logger.hpp:84
void flushOn(LogLevel level) noexcept
Flushes the sinks after every message at level or above.
Definition Logger.hpp:44
void warn(std::format_string< Args... > format, Args &&... args) noexcept
Definition Logger.hpp:73
Logger & operator=(const Logger &)=delete
void debug(std::format_string< Args... > format, Args &&... args) noexcept
Definition Logger.hpp:71
LogLevel getFlushLevel() const noexcept
Definition Logger.hpp:45
Logger(std::string name, LogLevel level=LogLevel::Trace)
Creates a logger without sinks; add them with addSink().
void log(LogLevel level, std::string_view message, const SourceLocation &source={}) noexcept
Logs message as is, without formatting.
void info(std::string_view message) noexcept
Definition Logger.hpp:83
void info(std::format_string< Args... > format, Args &&... args) noexcept
Definition Logger.hpp:72
void trace(std::format_string< Args... > format, Args &&... args) noexcept
Logs at a fixed level: trace(), debug(), info(), warn(), error() and fatal().
Definition Logger.hpp:70
Logger(const Logger &)=delete
void vlog(LogLevel level, const SourceLocation &source, std::string_view category, std::string_view format, std::format_args args) noexcept
Same as log() with a runtime format string, for wrappers.
void error(std::format_string< Args... > format, Args &&... args) noexcept
Definition Logger.hpp:74
bool removeSink(const std::shared_ptr< ISink > &sink) noexcept
Removes sink; returns false if it was not attached.
void flush() noexcept
Flushes every sink.
bool shouldLog(LogLevel level) const noexcept
Whether a message at level would be logged.
Definition Logger.hpp:40
void addSink(std::shared_ptr< ISink > sink, RingBufferSink &history)
Adds sink after replaying the messages kept by history into it.
const std::string & getName() const noexcept
Definition Logger.hpp:33
void addSink(std::shared_ptr< ISink > sink)
LogLevel getLevel() const noexcept
Definition Logger.hpp:38
void fatal(std::format_string< Args... > format, Args &&... args) noexcept
Definition Logger.hpp:75
void debug(std::string_view message) noexcept
Definition Logger.hpp:82
void clearSinks() noexcept
void error(std::string_view message) noexcept
Definition Logger.hpp:85
Keeps the latest messages in memory, to replay them into another sink later.
Definition RingBufferSink.hpp:12
Thread-safe logging: loggers, sinks, patterns and macros.
Definition Terminal.hpp:8
LogLevel
Severity of a message, from Trace to Fatal; Off disables logging.
Definition LogLevel.hpp:11
A log record as passed to the sinks.
Definition LogMessage.hpp:18
File, function and line of a log call.
Definition SourceLocation.hpp:6