Logging#

For logging, the following logging macros are provided:

  • MSGPACK_RPC_TRACE

  • MSGPACK_RPC_DEBUG

  • MSGPACK_RPC_INFO

  • MSGPACK_RPC_WARN

  • MSGPACK_RPC_ERROR

  • MSGPACK_RPC_CRITICAL

These can be used with msgpack_rpc::logging::Logger class.

msgpack_rpc::logging::Logger objects can be created using msgpack_rpc::logging::Logger::create() function. Examples to create loggers can be found in

APIs of Logging#

MSGPACK_RPC_TRACE(LOGGER_PTR, ...)#

Write a trace log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

MSGPACK_RPC_DEBUG(LOGGER_PTR, ...)#

Write a debug log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

MSGPACK_RPC_INFO(LOGGER_PTR, ...)#

Write a information log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

MSGPACK_RPC_WARN(LOGGER_PTR, ...)#

Write a warning log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

MSGPACK_RPC_ERROR(LOGGER_PTR, ...)#

Write a error log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

MSGPACK_RPC_CRITICAL(LOGGER_PTR, ...)#

Write a critical log.

Remaining arguments are the format of the log body and its arguments, or the log body itself.

Parameters:
  • LOGGER_PTR[in] Pointer to the logger.

class Logger#

Class to write logs.

Note

This class is assumed to be used in the following logging macros.

Public Functions

inline Logger(std::shared_ptr<ILogSink> sink, LogLevel output_log_level)#

Constructor.

Parameters:
  • sink[in] Log sink.

  • output_log_level[in] Log level to write logs.

inline LogLevel output_log_level() const noexcept#

Get the log level to write logs.

Returns:

Log level.

template<typename Body>
inline void write(SourceLocationView location, LogLevel level, Body &&body)#

Write a log.

Template Parameters:

Body – Type of the body of the log. (Must be convertible to std::string_view.)

Parameters:
  • location[in] Location in source codes.

  • level[in] Log level.

  • body[in] Body of the log.

template<typename ...Args>
inline void write(SourceLocationView location, LogLevel level, fmt::format_string<Args...> format, Args&&... args)#

Write a log with formatting.

Template Parameters:

Args – Type of arguments of the format of the body.

Parameters:
  • location[in] Location in source codes.

  • level[in] Log level.

  • format[in] Format of the body.

  • args[in] Arguments of the format of the body.

Public Static Functions

static inline std::shared_ptr<Logger> create(const config::LoggingConfig &config = config::LoggingConfig())#

Create a logger.

Parameters:

config[in] Configuration of logging.

Returns:

Logger.

static inline std::shared_ptr<Logger> create(std::shared_ptr<ILogSink> sink, LogLevel output_log_level = LogLevel::INFO)#

Create a logger.

Parameters:
  • sink[in] Log sink.

  • output_log_level[in] Log level to write logs.

Returns:

Logger.

enum class msgpack_rpc::logging::LogLevel : std::uint8_t#

Enumeration of log levels.

Values:

enumerator TRACE#

Trace. (Internal operations to send and receive messages.)

enumerator DEBUG#

Debug. (Log of messages, initialization and finalization of clients and servers.)

enumerator INFO#

Information. (Not used in this library.)

enumerator WARN#

Warnings. (Unexpected conditions which don’t stop operations.)

enumerator ERROR#

Error. (Unexpected conditions which stop some operations in communication.)

enumerator CRITICAL#

Critical. (Unexpected conditions which can stop all operations in communication.)

class ILogSink#

Interface of log sinks to write logs.

Subclassed by msgpack_rpc::logging::impl::spdlog_backend::SpdlogLogSink

Public Functions

virtual ~ILogSink() noexcept = default#

Destructor.

virtual void write(SourceLocationView location, LogLevel level, std::string_view body) = 0#

Write a log.

Parameters:
  • location[in] Location in source codes.

  • level[in] Log level.

  • body[in] Body of log.

class SourceLocationView#

Class of locations in source codes.

Public Functions

inline constexpr SourceLocationView(std::string_view file_path, std::uint32_t line, std::string_view function) noexcept#

Constructor.

Note

This class doesn’t manage memory of file paths.

Parameters:
  • file_path[in] File path.

  • line[in] Line number.

  • function[in] Function name.

inline std::string_view file_path() const noexcept#

Get the file path.

Returns:

File path.

inline std::string_view function() const noexcept#

Get the function name.

Returns:

Function name.

inline std::uint32_t line() const noexcept#

Get the line number.

Returns:

Line number.

MSGPACK_RPC_CURRENT_SOURCE_LOCATION()#

Macro to get the current location in source codes.