Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
Logger Class Reference

Logging facade: formats [time] [LEVEL] [component] message, filters by level, and forwards to a single sink (typically a CompositeSink). More...

#include <Logger.hpp>

+ Collaboration diagram for Logger:

Public Member Functions

 Logger (LogLevel threshold=LogLevel::Debug)
 
void setSink (std::unique_ptr< ILogSink > sink)
 
void setThreshold (LogLevel threshold)
 
void debug (std::string_view component, std::string_view msg)
 
void info (std::string_view component, std::string_view msg)
 
void warn (std::string_view component, std::string_view msg)
 
void error (std::string_view component, std::string_view msg)
 

Private Member Functions

void _log (LogLevel level, std::string_view component, std::string_view msg)
 

Private Attributes

std::unique_ptr< ILogSink_sink
 
LogLevel _threshold
 

Detailed Description

Logging facade: formats [time] [LEVEL] [component] message, filters by level, and forwards to a single sink (typically a CompositeSink).

Sink and threshold are injected (Dependency Injection). Messages below the threshold are dropped before formatting.

See also
server issue #127 — Logger system.

Definition at line 17 of file Logger.hpp.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( LogLevel  threshold = LogLevel::Debug)
explicit

Definition at line 37 of file Logger.cpp.

Member Function Documentation

◆ _log()

void Logger::_log ( LogLevel  level,
std::string_view  component,
std::string_view  msg 
)
private

Definition at line 41 of file Logger.cpp.

References _levelName(), _sink, _threshold, and _timestamp().

Referenced by debug(), error(), info(), and warn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ debug()

void Logger::debug ( std::string_view  component,
std::string_view  msg 
)

Definition at line 50 of file Logger.cpp.

References _log(), and Debug.

Referenced by LogObserver::onBroadcast(), LogObserver::onLineReceived(), LogObserver::onLineSent(), LogObserver::onPlayerInventoryChanged(), LogObserver::onPlayerMoved(), LogObserver::onResourceDropped(), LogObserver::onResourceTaken(), and LogObserver::onTileChanged().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error()

void Logger::error ( std::string_view  component,
std::string_view  msg 
)

Definition at line 65 of file Logger.cpp.

References _log(), and Error.

+ Here is the call graph for this function:

◆ info()

void Logger::info ( std::string_view  component,
std::string_view  msg 
)

Definition at line 55 of file Logger.cpp.

References _log(), and Info.

Referenced by Server::_handleGameOver(), LogObserver::onClientConnected(), LogObserver::onClientDisconnected(), LogObserver::onEggDied(), LogObserver::onEggHatched(), LogObserver::onEggLaid(), LogObserver::onGameEnd(), LogObserver::onIncantationEnd(), LogObserver::onIncantationStart(), LogObserver::onInitialEggSpawned(), LogObserver::onPlayerAdded(), LogObserver::onPlayerEjected(), LogObserver::onPlayerLevelUp(), LogObserver::onPlayerRemoved(), and Server::run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSink()

void Logger::setSink ( std::unique_ptr< ILogSink sink)

Definition at line 39 of file Logger.cpp.

References _sink.

Referenced by Server::Server().

+ Here is the caller graph for this function:

◆ setThreshold()

void Logger::setThreshold ( LogLevel  threshold)
inline

Definition at line 22 of file Logger.hpp.

References _threshold.

◆ warn()

void Logger::warn ( std::string_view  component,
std::string_view  msg 
)

Definition at line 60 of file Logger.cpp.

References _log(), and Warn.

+ Here is the call graph for this function:

Member Data Documentation

◆ _sink

std::unique_ptr<ILogSink> Logger::_sink
private

Definition at line 32 of file Logger.hpp.

Referenced by _log(), and setSink().

◆ _threshold

LogLevel Logger::_threshold
private

Definition at line 33 of file Logger.hpp.

Referenced by _log(), and setThreshold().


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