HomeWaterLeaksDetection
Logger Class Reference

#include <Logger.h>

Public Member Functions

void addEntity (ILoggable *log)
 Adds another class to the logging system. More...
 
void update () override
 Updates the class. More...
 

Static Public Member Functions

static LoggergetInstance ()
 Returns the instance of the class. More...
 

Private Member Functions

 Logger ()
 Constructor of the class. More...
 
 Logger (Logger const &)
 Copy constructor of the class. More...
 
Loggeroperator= (Logger const &)
 Assignment operator of the class. More...
 

Private Attributes

std::vector< ILoggable * > logs
 collection of classes that are registered in the logging system More...
 
TimePeriod timePeriod = LOG_PERIOD
 time period for recognizing when the log should be printed out More...
 

Static Private Attributes

static Loggerinstance = NULL
 the instance of the class More...
 

Detailed Description

Author
silhavyj A17B0362P

This class sepresents a controller for the logging part of the system. It is mainly used for debugging and troubleshooting.

Definition at line 20 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/2]

Logger::Logger ( )
inlineprivate

Constructor of the class.

Definition at line 31 of file Logger.h.

31 {};

Referenced by getInstance().

◆ Logger() [2/2]

Logger::Logger ( Logger const &  )
inlineprivate

Copy constructor of the class.

Definition at line 34 of file Logger.h.

34 {};

Member Function Documentation

◆ addEntity()

void Logger::addEntity ( ILoggable log)

Adds another class to the logging system.

Parameters
loganother class to be added

Definition at line 10 of file Logger.cpp.

10  {
11  logs.push_back(log);
12 }

References logs.

Referenced by setup().

◆ getInstance()

Logger * Logger::getInstance ( )
static

Returns the instance of the class.

If the instance has not been created, it will create it and then return it.

Returns
the instance of the class

Definition at line 5 of file Logger.cpp.

5  {
6  if (instance == NULL) instance = new Logger;
7  return instance;
8 }

References instance, and Logger().

Referenced by setup().

◆ operator=()

Logger& Logger::operator= ( Logger const &  )
inlineprivate

Assignment operator of the class.

Definition at line 37 of file Logger.h.

37 { return *this; }

◆ update()

void Logger::update ( )
overridevirtual

Updates the class.

If the logging period has passed, it will go over all the classes in the collection and print the logs out to the terminal one by one.

Implements IControllable.

Definition at line 14 of file Logger.cpp.

14  {
15  if (timePeriod.isActive()) {
16  Serial.println();
17  for (const auto log : logs) {
18  Serial.print("[");
19  Serial.print(FORMAT_TIME(millis()));
20  Serial.print("]");
21  Serial.print(log->getLogID());
22  Serial.println(log->getLogDescription());
23  }
24  }
25 }

References FORMAT_TIME, TimePeriod::isActive(), logs, and timePeriod.

Member Data Documentation

◆ instance

Logger * Logger::instance = NULL
staticprivate

the instance of the class

Definition at line 24 of file Logger.h.

Referenced by getInstance().

◆ logs

std::vector<ILoggable*> Logger::logs
private

collection of classes that are registered in the logging system

Definition at line 25 of file Logger.h.

Referenced by addEntity(), and update().

◆ timePeriod

TimePeriod Logger::timePeriod = LOG_PERIOD
private

time period for recognizing when the log should be printed out

Definition at line 26 of file Logger.h.

Referenced by update().


The documentation for this class was generated from the following files:
FORMAT_TIME
#define FORMAT_TIME(time)
Converts a time in milliseconds into a formatted string.
Definition: DateTime.h:141
Logger::instance
static Logger * instance
the instance of the class
Definition: Logger.h:24
Logger::timePeriod
TimePeriod timePeriod
time period for recognizing when the log should be printed out
Definition: Logger.h:26
TimePeriod::isActive
int isActive()
Returns information if the period of time has passed.
Definition: TimePeriod.cpp:7
Logger::Logger
Logger()
Constructor of the class.
Definition: Logger.h:31
Logger::logs
std::vector< ILoggable * > logs
collection of classes that are registered in the logging system
Definition: Logger.h:25