Design Pattern Examples
Overview of object-oriented design patterns
Logger Class Reference

Represents the logger object to be used in the program. More...

#include <Bridge_Logger.h>

Collaboration diagram for Logger:
Collaboration graph

Public Types

enum  LoggerTypes { ToNull , ToFile , ToConsole }
 A value passed to Logger.Logger() constructor to specify the type of logger to create. More...
 

Public Member Functions

 Logger (LoggerTypes loggerType)
 Constructor that takes a LoggerTypes value to create a new Logger class.
 
 Logger (const std::string &filename)
 Constructor that creates a file logger.
 
void LogTrace (std::string message)
 
void LogInfo (std::string message)
 Log informational messages to the configured output.
 
void LogError (std::string message)
 Log error messages to the configured output.
 

Private Attributes

std::unique_ptr< ILogger_logger
 

Detailed Description

Represents the logger object to be used in the program.

This class wraps different implementations of loggers to show the Bridge Pattern.

Definition at line 22 of file Bridge_Logger.h.

Member Enumeration Documentation

◆ LoggerTypes

A value passed to Logger.Logger() constructor to specify the type of logger to create.

Enumerator
ToNull 

Log to nowhere, that is, throw out all logging. No additional parameters.

ToFile 

Log to a file. One additional parameter: the name of the file to log to.

ToConsole 

Log to the console. No additional parameters.

Definition at line 33 of file Bridge_Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/2]

Logger ( LoggerTypes  loggerType)

Constructor that takes a LoggerTypes value to create a new Logger class.

Parameters
loggerTypeA value from the LoggerTypes enum specifying the type of logger object to create.

<exception name="exception>Logger.ToFile type was specified but no filename was given. Use Logger(const std::string&) instead.

Definition at line 24 of file Bridge_Logger.cpp.

References Logger::_logger, ConsoleLogger::CreateLogger(), NullLogger::CreateLogger(), Logger::ToConsole, Logger::ToFile, and Logger::ToNull.

◆ Logger() [2/2]

Logger ( const std::string &  filename)

Constructor that creates a file logger.

Parameters
filenamePath to a file to create for the file logger.

Definition at line 53 of file Bridge_Logger.cpp.

References Logger::_logger, and FileLogger::CreateLogger().

Member Function Documentation

◆ LogError()

void LogError ( std::string  message)

Log error messages to the configured output.

Parameters
messageThe message to log.

Definition at line 84 of file Bridge_Logger.cpp.

References Logger::_logger.

◆ LogInfo()

void LogInfo ( std::string  message)

Log informational messages to the configured output.

Parameters
messageThe message to log.

Definition at line 73 of file Bridge_Logger.cpp.

References Logger::_logger.

◆ LogTrace()

void LogTrace ( std::string  message)

Log trace messages to the configured output.

Parameters
messageThe message to log.

Definition at line 62 of file Bridge_Logger.cpp.

References Logger::_logger.

Member Data Documentation

◆ _logger

std::unique_ptr<ILogger> _logger
private

The documentation for this class was generated from the following files: