carl  24.04
Computer ARithmetic Library
carl::logging::Logger Class Reference

Main logger class. More...

#include <Logger.h>

Inheritance diagram for carl::logging::Logger:
Collaboration diagram for carl::logging::Logger:

Public Member Functions

bool has (const std::string &id) const noexcept
 Check if a Sink with the given id has been installed. More...
 
void configure (const std::string &id, std::shared_ptr< Sink > sink)
 Installs the given sink. More...
 
void configure (const std::string &id, const std::string &filename)
 Installs a FileSink. More...
 
void configure (const std::string &id, std::ostream &os)
 Installs a StreamSink. More...
 
Filterfilter (const std::string &id) noexcept
 Retrieves the Filter for some Sink. More...
 
const std::shared_ptr< Formatter > & formatter (const std::string &id) noexcept
 Retrieves the Formatter for some Sink. More...
 
void formatter (const std::string &id, std::shared_ptr< Formatter > fmt) noexcept
 Overwrites the Formatter for some Sink. More...
 
void resetFormatter () noexcept
 Reconfigures all Formatter objects. More...
 
bool visible (LogLevel level, const std::string &channel) const noexcept
 Checks whether a log message would be visible for some sink. More...
 
void log (LogLevel level, const std::string &channel, const std::stringstream &ss, const RecordInfo &info)
 Logs a message. More...
 

Static Public Member Functions

static LoggergetInstance ()
 Returns the single instance of this class by reference. More...
 

Private Attributes

std::map< std::string, std::tuple< std::shared_ptr< Sink >, Filter, std::shared_ptr< Formatter > > > mData
 Mapping from channels to associated logging classes. More...
 
std::mutex mMutex
 Logging mutex to ensure thread-safe logging. More...
 

Detailed Description

Main logger class.

Definition at line 74 of file Logger.h.

Member Function Documentation

◆ configure() [1/3]

void carl::logging::Logger::configure ( const std::string &  id,
const std::string &  filename 
)
inline

Installs a FileSink.

Parameters
idSink identifier.
filenameFilename passed to the FileSink.

Definition at line 105 of file Logger.h.

Here is the call graph for this function:

◆ configure() [2/3]

void carl::logging::Logger::configure ( const std::string &  id,
std::ostream &  os 
)
inline

Installs a StreamSink.

Parameters
idSink identifier.
osOutput stream passed to the StreamSink.

Definition at line 113 of file Logger.h.

Here is the call graph for this function:

◆ configure() [3/3]

void carl::logging::Logger::configure ( const std::string &  id,
std::shared_ptr< Sink sink 
)
inline

Installs the given sink.

If a Sink with this name is already present, it is overwritten.

Parameters
idSink identifier.
sinkSink.

Definition at line 96 of file Logger.h.

Here is the caller graph for this function:

◆ filter()

Filter& carl::logging::Logger::filter ( const std::string &  id)
inlinenoexcept

Retrieves the Filter for some Sink.

Parameters
idSink identifier.
Returns
Filter.

Definition at line 121 of file Logger.h.

Here is the caller graph for this function:

◆ formatter() [1/2]

const std::shared_ptr<Formatter>& carl::logging::Logger::formatter ( const std::string &  id)
inlinenoexcept

Retrieves the Formatter for some Sink.

Parameters
idSink identifier.
Returns
Formatter.

Definition at line 131 of file Logger.h.

◆ formatter() [2/2]

void carl::logging::Logger::formatter ( const std::string &  id,
std::shared_ptr< Formatter fmt 
)
inlinenoexcept

Overwrites the Formatter for some Sink.

Parameters
idSink identifier.
fmtNew Formatter.

Definition at line 141 of file Logger.h.

◆ getInstance()

static Logger & carl::Singleton< Logger >::getInstance ( )
inlinestaticinherited

Returns the single instance of this class by reference.

If there is no instance yet, a new one is created.

Definition at line 45 of file Singleton.h.

◆ has()

bool carl::logging::Logger::has ( const std::string &  id) const
inlinenoexcept

Check if a Sink with the given id has been installed.

Parameters
idSink identifier.
Returns
If a Sink with this id is present.

Definition at line 87 of file Logger.h.

◆ log()

void carl::logging::Logger::log ( LogLevel  level,
const std::string &  channel,
const std::stringstream &  ss,
const RecordInfo info 
)
inline

Logs a message.

Parameters
levelLogLevel.
channelChannel name.
ssMessage to be logged.
infoAuxiliary information.

Definition at line 177 of file Logger.h.

Here is the caller graph for this function:

◆ resetFormatter()

void carl::logging::Logger::resetFormatter ( )
inlinenoexcept

Reconfigures all Formatter objects.

This should be done once after all configuration is finished.

Definition at line 151 of file Logger.h.

Here is the caller graph for this function:

◆ visible()

bool carl::logging::Logger::visible ( LogLevel  level,
const std::string &  channel 
) const
inlinenoexcept

Checks whether a log message would be visible for some sink.

If this is not the case, we do not need to render it at all.

Parameters
levelLogLevel.
channelChannel name.

Definition at line 162 of file Logger.h.

Here is the caller graph for this function:

Field Documentation

◆ mData

std::map<std::string, std::tuple<std::shared_ptr<Sink>, Filter, std::shared_ptr<Formatter> > > carl::logging::Logger::mData
private

Mapping from channels to associated logging classes.

Definition at line 77 of file Logger.h.

◆ mMutex

std::mutex carl::logging::Logger::mMutex
private

Logging mutex to ensure thread-safe logging.

Definition at line 79 of file Logger.h.


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