SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::services::Logger Class Reference

A thread-safe Singleton class responsible for logging system events. More...

#include <Logger.hxx>

Inheritance diagram for svcs::services::Logger:
svcs::services::IObserver

Public Member Functions

 Logger (const std::string &name)
 Constructor.
 ~Logger () override
 Destructor.
void update (const Event &event) override
 Method called by the Subject to notify the observer with an event.
void notify (const Event &event) override
 Method called by the subject to notify the observer.
void debug (const std::string &message)
 Logs a message at the DEBUG level.
void info (const std::string &message)
 Logs a message at the INFO level.
void warn (const std::string &message)
 Logs a message at the WARN level.
void error (const std::string &message)
 Logs a message at the ERROR level.
void fatal (const std::string &message)
 Logs a message at the FATAL level.
void setLevel (LogLevel level)
 Sets the minimum log level for this instance.
LogLevel getLevel () const
 Retrieves the current minimum log level.
void setPattern (const std::string &pattern)
 Sets the output formatting pattern for messages.
void flush ()
 Forces all buffered log output to be written immediately (e.g., to disk).
Public Member Functions inherited from svcs::services::IObserver
virtual ~IObserver ()=default
 Default virtual destructor.

Static Public Member Functions

static std::shared_ptr< LoggergetInstance (const std::string &name)
 Retrieves the Singleton instance of the Logger for the given name.
static void clearInstances ()
 Clears all registered Singleton instances.

Detailed Description

A thread-safe Singleton class responsible for logging system events.

Implements the IObserver interface to automatically receive and process events generated by commands and core components.

Constructor & Destructor Documentation

◆ Logger()

svcs::services::Logger::Logger ( const std::string & name)
explicit

Constructor.

Private/protected access is typically enforced in the Singleton implementation file.

Parameters
nameThe unique name for this logger instance.

Member Function Documentation

◆ clearInstances()

void svcs::services::Logger::clearInstances ( )
static

Clears all registered Singleton instances.

Used primarily for cleanup in testing environments.

◆ debug()

void svcs::services::Logger::debug ( const std::string & message)

Logs a message at the DEBUG level.

Parameters
messageThe content of the log message.

◆ error()

void svcs::services::Logger::error ( const std::string & message)

Logs a message at the ERROR level.

Parameters
messageThe content of the log message.

◆ fatal()

void svcs::services::Logger::fatal ( const std::string & message)

Logs a message at the FATAL level.

Parameters
messageThe content of the log message.

◆ getInstance()

std::shared_ptr< Logger > svcs::services::Logger::getInstance ( const std::string & name)
static

Retrieves the Singleton instance of the Logger for the given name.

Creates and registers a new instance if one does not already exist.

Parameters
nameThe name of the desired logger instance.
Returns
A shared pointer to the Logger instance.

◆ getLevel()

LogLevel svcs::services::Logger::getLevel ( ) const
nodiscard

Retrieves the current minimum log level.

Returns
The current LogLevel.

◆ info()

void svcs::services::Logger::info ( const std::string & message)

Logs a message at the INFO level.

Parameters
messageThe content of the log message.

◆ notify()

void svcs::services::Logger::notify ( const Event & event)
overridevirtual

Method called by the subject to notify the observer.

Parameters
eventThe Event structure containing the notification data.
Deprecated
Note: This method is likely redundant with update(const Event& event) based on the IObserver definition. It should ideally map to the same logic as update.

Implements svcs::services::IObserver.

◆ setLevel()

void svcs::services::Logger::setLevel ( LogLevel level)

Sets the minimum log level for this instance.

Parameters
levelThe new LogLevel.

◆ setPattern()

void svcs::services::Logger::setPattern ( const std::string & pattern)

Sets the output formatting pattern for messages.

Parameters
patternThe new format string (implementation details depend on pattern syntax).

◆ update()

void svcs::services::Logger::update ( const Event & event)
overridevirtual

Method called by the Subject to notify the observer with an event.

Maps the Event::Type to a LogLevel and processes the message.

Parameters
eventThe Event structure containing the notification data.

Implements svcs::services::IObserver.

◆ warn()

void svcs::services::Logger::warn ( const std::string & message)

Logs a message at the WARN level.

Parameters
messageThe content of the log message.

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