CIRCT  20.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
esi::TSLogger Class Referenceabstract

A thread-safe logger which calls functions implemented by subclasses. More...

#include <Logging.h>

Inheritance diagram for esi::TSLogger:
Inheritance graph
[legend]
Collaboration diagram for esi::TSLogger:
Collaboration graph
[legend]

Public Member Functions

void log (Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details) override final
 Grabs the lock and calls logImpl. More...
 
 Logger (bool debugEnabled)
 
- Public Member Functions inherited from esi::Logger
 Logger (bool debugEnabled)
 
virtual ~Logger ()=default
 
bool getDebugEnabled ()
 
virtual void error (const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
 Report an error. More...
 
virtual void warning (const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
 Report a warning. More...
 
virtual void info (const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
 Report an informational message. More...
 
void debug (const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
 Report a debug message. More...
 
void debug (std::function< void(std::string &subsystem, std::string &msg, std::unique_ptr< std::map< std::string, std::any >> &details)> debugFunc)
 Call the debug function callback only if debug is enabled then log a debug message. More...
 

Protected Member Functions

virtual void logImpl (Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details)=0
 Subclasses must implement this method to log messages. More...
 
- Protected Member Functions inherited from esi::Logger
virtual void debugImpl (const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details)
 Overrideable version of debug. Only gets called if debug is enabled. More...
 
virtual void debugImpl (std::function< void(std::string &subsystem, std::string &msg, std::unique_ptr< std::map< std::string, std::any >> &details)> debugFunc)
 Overrideable version of debug. Only gets called if debug is enabled. More...
 

Protected Attributes

std::mutex mutex
 Mutex to protect the stream from interleaved logging writes. More...
 
- Protected Attributes inherited from esi::Logger
bool debugEnabled = false
 Enable or disable debug messages. More...
 

Additional Inherited Members

- Public Types inherited from esi::Logger
enum class  Level { Debug , Info , Warning , Error }
 

Detailed Description

A thread-safe logger which calls functions implemented by subclasses.

Only protects the log method. If subclasses override other methods and need to protect them, they need to do that themselves.

Definition at line 126 of file Logging.h.

Member Function Documentation

◆ log()

void TSLogger::log ( Level  level,
const std::string &  subsystem,
const std::string &  msg,
const std::map< std::string, std::any > *  details 
)
finaloverridevirtual

Grabs the lock and calls logImpl.

Implements esi::Logger.

Definition at line 23 of file Logging.cpp.

References logImpl(), and mutex.

◆ Logger()

esi::Logger::Logger
inline

Definition at line 44 of file Logging.h.

◆ logImpl()

virtual void esi::TSLogger::logImpl ( Level  level,
const std::string &  subsystem,
const std::string &  msg,
const std::map< std::string, std::any > *  details 
)
protectedpure virtual

Subclasses must implement this method to log messages.

Implemented in esi::StreamLogger.

Referenced by log().

Member Data Documentation

◆ mutex

std::mutex esi::TSLogger::mutex
protected

Mutex to protect the stream from interleaved logging writes.

Definition at line 141 of file Logging.h.

Referenced by log().


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