33#include <fmt/format.h>
62 [[nodiscard]]
static std::shared_ptr<Logger>
create(
75 [[nodiscard]]
static std::shared_ptr<Logger>
create(
76 std::shared_ptr<ILogSink> sink,
99 template <
typename Body>
102 sink_->write(location, level,
104 std::string_view(std::forward<Body>(body)));
117 template <
typename... Args>
119 fmt::format_string<Args...> format, Args&&... args) {
121 fmt::memory_buffer buffer;
122 fmt::format_to(std::back_inserter(buffer), format,
123 std::forward<Args>(args)...);
124 sink_->write(location, level,
125 std::string_view(buffer.data(), buffer.size()));
157#define MSGPACK_RPC_LOG(LOGGER_PTR, LEVEL, ...) \
159 if (LEVEL >= (LOGGER_PTR)->output_log_level()) { \
161 ->write(MSGPACK_RPC_CURRENT_SOURCE_LOCATION(), LEVEL, \
174#define MSGPACK_RPC_TRACE(LOGGER_PTR, ...) \
176 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::TRACE, __VA_ARGS__)
186#define MSGPACK_RPC_DEBUG(LOGGER_PTR, ...) \
188 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::DEBUG, __VA_ARGS__)
198#define MSGPACK_RPC_INFO(LOGGER_PTR, ...) \
200 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::INFO, __VA_ARGS__)
210#define MSGPACK_RPC_WARN(LOGGER_PTR, ...) \
212 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::WARN, __VA_ARGS__)
222#define MSGPACK_RPC_ERROR(LOGGER_PTR, ...) \
224 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::ERROR, __VA_ARGS__)
234#define MSGPACK_RPC_CRITICAL(LOGGER_PTR, ...) \
236 LOGGER_PTR, ::msgpack_rpc::logging::LogLevel::CRITICAL, __VA_ARGS__)
Class of Logging configuration.
void write(SourceLocationView location, LogLevel level, fmt::format_string< Args... > format, Args &&... args)
Write a log with formatting.
LogLevel output_log_level_
Log level.
LogLevel output_log_level() const noexcept
Get the log level to write logs.
static std::shared_ptr< Logger > create(const config::LoggingConfig &config=config::LoggingConfig())
Create a logger.
static std::shared_ptr< Logger > create(std::shared_ptr< ILogSink > sink, LogLevel output_log_level=LogLevel::INFO)
Create a logger.
std::shared_ptr< ILogSink > sink_
Log sink.
Logger(std::shared_ptr< ILogSink > sink, LogLevel output_log_level)
Constructor.
void write(SourceLocationView location, LogLevel level, Body &&body)
Write a log.
Class of locations in source codes.
Definition of ILogSink class.
Definition of LogLevel enumeration.
Declaration of functions to create log sinks.
Definition of LoggingConfig class.
Namespace of configurations.
LogLevel
Enumeration of log levels.
@ INFO
Information. (Not used in this library.)
std::shared_ptr< ILogSink > create_log_sink_from_config(const config::LoggingConfig &config)
Create a log sink from a configuration.
Definition of SourceLocationView class.