Shortcuts

Template Class Logger

Class Documentation

template<LogLevel MinLevel, size_t BufferSize, typename LockPolicy>
class ripple::Logger

Simple logger class, which logs messages when the level of the message is more tha the MinLevel.

The messages are buffered in a buffer of BufferSize, and if a message wont fit in the buffer, the buffer is flushed.

This logger is not designed to be high-performance, since in release the only messages that will be logged in the fast path are error messages, and info messages will be in the slow path, so safety and flexibility are more important.

The logger uses an instance of the locking policy to lock when logging.

Template Parameters
  • MinLevel: The minimum level for message logging.

  • BufferSize: The size of the message buffer.

  • LockPolicy: The locking polcity for the lock.

Public Functions

~Logger()

Flushes pending logs in the stream and closes the logging file.

Logger(Logger&&) noexcept = default

Defaulted move construction.

auto operator=(Logger&&) noexcept -> Logger& = default

Delete move assignment, since we can only have a single logger.

Logger() = delete

Deleted , create through create().

Logger(const Logger&) = delete

Delete copy construction, since there can only be one logger.

auto operator=(const Logger&) = delete

Delete copy assignment, since we can only have a single logger.

auto flush() -> void

Flushes the pending messages in the logger to the logging file.

Note that this claims the mutex to perform the write, so it should only be called to flush the logger if a termination happens.

template<LogLevel L, VoidLogEnable<L> = 0>
auto log(const std::string &message) noexcept -> void

Never logs the message, which should already be formatted.

This overload is enabled if the level L is more than the level of the logger, and will be compiled away.

Parameters
  • message: The message to log.

Template Parameters
  • L: The log level for the message.

template<LogLevel L, ValidLogEnable<L> = 0>
void log(const std::string &message)

Logs the message, which should already be formatted.

Note

This overload is only enabled if the level L is less than or equal to the level of the logger.

Parameters
  • message: The message to log.

Template Parameters
  • L: The log level for the message.

Public Static Functions

auto logger() noexcept -> Logger&

Accesses the global logger.

Return

A reference to the logger.

template<LogLevel L>
constexpr auto would_log() noexcept -> bool

Determines if the logger would log an error with level L.

Return

true of the logger would log for the given level.

Template Parameters
  • L: The level to check if would be logged.

Public Static Attributes

constexpr LogLevel level = MinLevel

Defines the level for the logger.

All messages logged below the level will become no-ops.

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples