ma::Logger::Device

Interface class used to write message sent by the logger. More...

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

Module

Inherited by

Public Functions#

Device() noexcept

~Device() noexcept

void
write(Message category, const char *msg) noexcept=0

Detailed Description#

To be effective, the Logger class needs a device. This device is used to write log messages.

A default implementation used to print messages on the standard std::cout and std::cerr streams is proposed and correspond to the following lines.

struct Console : Logger::Device
{
  virtual void write(Logger::Category category, const char* msg) _OPENMA_NOEXCEPT override
  {
    if (category == Logger::Info)
      std::cout << "INFO: " << msg << std::endl;
    else if (category == Logger::Warning)
      std::cout << "WARNING: " << msg << std::endl;
    else if (category == Logger::Error)
      std::cout << "ERROR: " << msg << std::endl;
  }
};

Only one device can be used at a time. To create your custom device you only need to inherit from the class Logger::Device and override the method Logger::Device::write(). To use this custom device with the logger, you have to use the method Device::setDevice().

Member Function Documentation#

ma::Logger::Device::Device ( ) noexcept

Default (empty) constructor

void ma::Logger::Device::write ( Message category , const char * msg ) noexcept [virtual]

The logger seng message to this method. The category input specifies if the message is for an information, a warning, or an error. The msg input is directly the string given to the functions info(), warning(), or error().

ma::Logger::Device::~Device ( ) noexcept [virtual]

Default (empty) destructor