CIRCT  20.0.0git
Public Member Functions | Private Attributes | List of all members
esi::StreamLogger Class Reference

A logger that writes to a C++ std::ostream. More...

#include <Logging.h>

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

Public Member Functions

 StreamLogger (Level minLevel, std::ostream &out, std::ostream &error)
 Create a stream logger that logs to the given output stream and error output stream. More...
 
 StreamLogger (Level minLevel)
 Create a stream logger that logs to stdout, stderr. More...
 
void logImpl (Level level, const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details) override
 Subclasses must implement this method to log messages. More...
 
- Public Member Functions inherited from esi::TSLogger
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...
 

Private Attributes

Level minLevel
 The minimum log level to emit. More...
 
std::ostream & outStream
 Everything except errors goes here. More...
 
std::ostream & errorStream
 Just for errors. More...
 

Additional Inherited Members

- Public Types inherited from esi::Logger
enum class  Level { Debug , Info , Warning , Error }
 
- 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 inherited from esi::TSLogger
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...
 

Detailed Description

A logger that writes to a C++ std::ostream.

Definition at line 145 of file Logging.h.

Constructor & Destructor Documentation

◆ StreamLogger() [1/2]

esi::StreamLogger::StreamLogger ( Level  minLevel,
std::ostream &  out,
std::ostream &  error 
)
inline

Create a stream logger that logs to the given output stream and error output stream.

Definition at line 149 of file Logging.h.

◆ StreamLogger() [2/2]

StreamLogger::StreamLogger ( Level  minLevel)

Create a stream logger that logs to stdout, stderr.

Definition at line 30 of file Logging.cpp.

Member Function Documentation

◆ logImpl()

void StreamLogger::logImpl ( Level  level,
const std::string &  subsystem,
const std::string &  msg,
const std::map< std::string, std::any > *  details 
)
overridevirtual

Subclasses must implement this method to log messages.

Implements esi::TSLogger.

Definition at line 34 of file Logging.cpp.

References esi::Logger::Debug, esi::Logger::Error, errorStream, esi::Logger::Info, minLevel, outStream, esi::toString(), and esi::Logger::Warning.

Member Data Documentation

◆ errorStream

std::ostream& esi::StreamLogger::errorStream
private

Just for errors.

Definition at line 165 of file Logging.h.

Referenced by logImpl().

◆ minLevel

Level esi::StreamLogger::minLevel
private

The minimum log level to emit.

Definition at line 160 of file Logging.h.

Referenced by logImpl().

◆ outStream

std::ostream& esi::StreamLogger::outStream
private

Everything except errors goes here.

Definition at line 163 of file Logging.h.

Referenced by logImpl().


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