3#ifndef BITSIM_UTILS_LOGGER_H
4#define BITSIM_UTILS_LOGGER_H
68void add_file_sink(
const std::string &filename,
bool truncate =
true);
88LoggerHandle *
handle(
const std::string &logger);
94void write(LoggerHandle *logger,
Level level, std::string_view message)
noexcept;
117 manipulator(stream_);
124 std::ostringstream stream_;
135#define BITSIM_LOG_TO(logger_name, level) \
136 if (auto *const bitsim_log_logger = \
139 static auto *const handle = ::bitsim::log::detail::handle(logger_name); \
142 !::bitsim::log::detail::enabled(bitsim_log_logger, level)) \
146 ::bitsim::log::detail::LogLine(bitsim_log_logger, level)
148#define BITSIM_LOG_TRACE BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::trace)
149#define BITSIM_LOG_DEBUG BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::debug)
150#define BITSIM_LOG_INFO BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::info)
151#define BITSIM_LOG_WARN BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::warn)
152#define BITSIM_LOG_ERROR BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::error)
153#define BITSIM_LOG_CRITICAL BITSIM_LOG_TO("bitsim", ::bitsim::log::Level::critical)
LogLine & operator=(const LogLine &)=delete
LogLine & operator<<(const T &value)
Definition logger.h:108
~LogLine()
Definition logger.h:106
LogLine(LoggerHandle *logger, Level level) noexcept
Definition logger.h:101
LogLine & operator<<(std::ostream &(*manipulator)(std::ostream &))
For std::endl and the other manipulators.
Definition logger.h:115
LogLine(const LogLine &)=delete
void write(LoggerHandle *logger, Level level, std::string_view message) noexcept
Write a message, without its trailing new lines.
Definition logger.cpp:141
bool enabled(LoggerHandle *logger, Level level) noexcept
Whether the logger writes messages of the given level.
Definition logger.cpp:136
LoggerHandle * handle(const std::string &logger)
The logger with the given name, made the first time. It lives until the program ends.
Definition logger.cpp:129
void add_file_sink(const std::string &filename, bool truncate)
Write the messages of every logger to a file as well.
Definition logger.cpp:189
Level
The severity of a message, and the lowest severity a logger writes.
Definition logger.h:44
@ trace
Definition logger.h:45
@ warn
Definition logger.h:48
@ off
Definition logger.h:51
@ critical
Definition logger.h:50
@ debug
Definition logger.h:46
@ info
Definition logger.h:47
@ error
Definition logger.h:49
Level get_level(const std::string &logger)
The level of the logger with the given name, making it if needed.
Definition logger.cpp:182
void set_level(Level level)
Set the level of every logger, and of the loggers made later.
Definition logger.cpp:165
void flush()
Write out what the sinks hold.
Definition logger.cpp:210
void set_pattern(const std::string &pattern)
Set the format of the messages of every sink, in spdlog's pattern syntax. The default is "[%Y-%m-%d %...
Definition logger.cpp:198