ma::Logger

Class to centralize log messages and write them to a device. More...

Header
#include <openma/base/logger.h>

Module

Public Functions#

void
prepareAndSendMessage(Message category, const char *msg,...)

void
sendMessage(Message category, const char *msg)

~Logger() noexcept

Static Public Members#

void
mute(bool active) noexcept

void
setDevice(Device *output) noexcept

Logger &

Detailed Description#

Three categories are available and could be used as proposed below:

  • Message::Info: For users' information or debugging
  • Message::Warning: For incorrect inputs in algorithms but still adatable.
  • Message::Error: For undesired behaviour which can break algorithms' logic.

Each logging category has a dedicated static function:

  • info()
  • warning()
  • error()

These functions send the given message to a Logger::Device set. This device has the role to write the message (in a console, a file, etc.). By default, the message are sent into the standard cout/cerr streams. To set a device, you have to use the method Logger::setDevice()

To disable the logger, you can use the method logger::mute().

Member Function Documentation#

ma::Logger::~Logger ( ) noexcept

Destructor Delete the set device

Logger & ma::Logger::instance ( ) [static]

Singleton

void ma::Logger::mute ( bool active ) noexcept [static]

Active/unactive the logger. If the logger is set to mute, all the messages are eaten and destroyed.

void ma::Logger::prepareAndSendMessage ( Message category , const char * msg , ... )

Send a message to the set device. If no device is set, a default one is created and send info messages to the std::cout stream and warning and error messages to the std::cerr stream. You can set a device using the method Logger::setDevice().

Compared to the method Logger::sendMessage(), this method creates also a string based on the given variadic arguments.

void ma::Logger::sendMessage ( Message category , const char * msg )

Send a message to the set device. If no device is set, a default one is created and send info messages to the std::cout stream and warning and error messages to the std::cerr stream. You can set a device using the method Logger::setDevice().

void ma::Logger::setDevice ( Device * output ) noexcept [static]

Set the device which will write the log messages. If a previous device was set, it will be deleted. The logger takes the ownership of the device.