EasyException
ee::Log Class Reference

This class manages all logging activity. All other logging features will depend on this class. More...

#include <ee/Log.hpp>

Static Public Member Functions

static void applyDefaultConfiguration (const std::string &logFolder="") noexcept
 This method applies the default configuration of this framework.
 
static void log (LogLevel logLevel, const std::string &classname, const std::string &method, const std::string &message, const std::vector< Note > &notes, const std::optional< std::shared_ptr< Stacktrace >> &stacktrace=std::nullopt) noexcept
 The basic log method, that stores a log entry for the caller thread in the log-thread map. More...
 
static void log (LogLevel logLevel, const Exception &exception) noexcept
 Converts the given exception into an LogEntry and stores that into the log. More...
 
static void log (LogLevel logLevel, const std::exception &exception) noexcept
 Converts the given exception into an LogEntry and stores that into the log list. More...
 
static bool check (bool condition, const std::string &method, const std::string &message, const std::vector< Note > &notes, const std::optional< std::shared_ptr< Stacktrace >> &stacktrace=std::nullopt) noexcept
 Checks the given condition and logs a warning in case that the condition fails. More...
 
static const std::map< std::thread::id, std::list< LogEntry > > & getLogThreadMap () noexcept
 Returns a reference to the log-thread map. Using it can be critical due to the multi-threaded-nature of this framework. More...
 
static void reset () noexcept
 Resets the log-thread map and removes all previously stored log entries. More...
 
static size_t getNumberOfLogEntries () noexcept
 Returns the number of log entries. More...
 
static void registerCallback (LogLevel logLevel, std::function< void(const LogEntry &)> callback) noexcept
 Registers the given callback for the given LogLevel. More...
 
static const std::map< LogLevel, std::function< void(const LogEntry &)> > & getCallbackMap () noexcept
 Returns a map containing the callback-LogLevel map. More...
 
static void removeCallbacks () noexcept
 Removes all registered callbacks.
 
static bool writeToFile (const std::string &filename, OutputFormat format=EASY_EXCEPTION_OUTPUT_FORMAT) noexcept
 Writes all logs into a file with the given name. More...
 
static void registerOutstream (LogLevel logLevel, std::ostream &outstream) noexcept
 Registers the given outstream with a specific log level. More...
 
static void removeOutstreams () noexcept
 Removes all registered out streams.
 
static const std::map< LogLevel, std::ostream * > & getOutstreams () noexcept
 Returns the map of outstreams. More...
 
static void registerLogRententionPolicy (std::shared_ptr< LogRetentionPolicy > policy) noexcept
 Registers a log retention policy. More...
 
static void removeLogRetentionPolicies () noexcept
 Removes all log retention policies.
 
static const std::map< uint8_t, std::shared_ptr< LogRetentionPolicy > > & getLogRetentionPolicies () noexcept
 Returns the map of log retention policies. More...
 
static void releaseLogs () noexcept
 Releases all logs that are not retained by the retention policies.
 
static std::map< LogLevel, size_t > countLogLevels () noexcept
 Counts all log levels and returns a map containing the different amounts. More...
 

Static Private Attributes

static std::recursive_mutex Mutex
 The mutex that manages the log-thread map. It must be locked every time the LogThreadMap is queried or modified.
 
static std::map< std::thread::id, std::list< LogEntry > > LogThreadMap
 The log-thread map that contains a list of LogEntries for each thread.
 
static std::map< LogLevel, std::function< void(const LogEntry &)> > CallbackMap
 This map can hold a single callback for each LogLevel.
 
static std::atomic_uint16_t SuspendLoggingCounter
 This boolean variable can be set to true to suspend logging for a short time period. More...
 
static std::map< LogLevel, std::ostream * > OutStreamMap
 This map contains the output streams that should be used for the specific LogLevels.
 
static std::map< uint8_t, std::shared_ptr< LogRetentionPolicy > > LogRetentionPolicies
 This map holds the log retention policies.
 

Friends

class SuspendLogging
 

Detailed Description

This class manages all logging activity. All other logging features will depend on this class.

Member Function Documentation

static bool ee::Log::check ( bool  condition,
const std::string &  method,
const std::string &  message,
const std::vector< Note > &  notes,
const std::optional< std::shared_ptr< Stacktrace >> &  stacktrace = std::nullopt 
)
staticnoexcept

Checks the given condition and logs a warning in case that the condition fails.

Parameters
conditionThe condition that must be false to log a warning.
methodThe method where the logging occured.
messageThe message to describe the incident.
notesA vector of notes describing more details.
stacktraceThe stacktrace.
Returns
The condition.
static std::map<LogLevel,size_t> ee::Log::countLogLevels ( )
staticnoexcept

Counts all log levels and returns a map containing the different amounts.

Returns
Map containing the count for each log level.
static const std::map<LogLevel,std::function<void(const LogEntry&)> >& ee::Log::getCallbackMap ( )
staticnoexcept

Returns a map containing the callback-LogLevel map.

Returns
Reference to the callback-LogLevel map.
static const std::map<uint8_t,std::shared_ptr<LogRetentionPolicy> >& ee::Log::getLogRetentionPolicies ( )
staticnoexcept

Returns the map of log retention policies.

Returns
Reference to the map of log retention policies.
static const std::map<std::thread::id, std::list<LogEntry> >& ee::Log::getLogThreadMap ( )
staticnoexcept

Returns a reference to the log-thread map. Using it can be critical due to the multi-threaded-nature of this framework.

Returns
Reference to the log-thread map.
static size_t ee::Log::getNumberOfLogEntries ( )
staticnoexcept

Returns the number of log entries.

Sums the number of all log entries from each thread.

Returns
The total number of log entries.
static const std::map<LogLevel, std::ostream*>& ee::Log::getOutstreams ( )
staticnoexcept

Returns the map of outstreams.

Returns
Reference to the map of outstreams.
static void ee::Log::log ( LogLevel  logLevel,
const std::string &  classname,
const std::string &  method,
const std::string &  message,
const std::vector< Note > &  notes,
const std::optional< std::shared_ptr< Stacktrace >> &  stacktrace = std::nullopt 
)
staticnoexcept

The basic log method, that stores a log entry for the caller thread in the log-thread map.

Parameters
logLevelThe log level of the log entry.
classnameThe classname of the log entry.
methodThe method name of the log entry.
messageThe message of the log entry.
notesA list of notes for the log entry.
stacktraceThe stacktrace for the log entry.
static void ee::Log::log ( LogLevel  logLevel,
const Exception exception 
)
staticnoexcept

Converts the given exception into an LogEntry and stores that into the log.

Parameters
logLevelThe log level to use.
exceptionThe exception to log.
static void ee::Log::log ( LogLevel  logLevel,
const std::exception &  exception 
)
staticnoexcept

Converts the given exception into an LogEntry and stores that into the log list.

Parameters
logLevelThe log level to use.
exceptionThe exception to convert.
static void ee::Log::registerCallback ( LogLevel  logLevel,
std::function< void(const LogEntry &)>  callback 
)
staticnoexcept

Registers the given callback for the given LogLevel.

Parameters
logLevelThe LogLevel to register the callback.
callbackThe callback to be executed for the given LogLevel.
static void ee::Log::registerLogRententionPolicy ( std::shared_ptr< LogRetentionPolicy policy)
staticnoexcept

Registers a log retention policy.

Parameters
policyThe policy to register.
static void ee::Log::registerOutstream ( LogLevel  logLevel,
std::ostream &  outstream 
)
staticnoexcept

Registers the given outstream with a specific log level.

All future logs in this loglevel will be printed into that outstream.

Parameters
logLevelThe log level where the printing should be executed.
outstreamThe out stream where the output should go into.
static void ee::Log::reset ( )
staticnoexcept

Resets the log-thread map and removes all previously stored log entries.

The log lists for each thread will remain because we can not remove them. Every thread stores a pointer to its log list and we cant remove that pointer afterwards.

static bool ee::Log::writeToFile ( const std::string &  filename,
OutputFormat  format = EASY_EXCEPTION_OUTPUT_FORMAT 
)
staticnoexcept

Writes all logs into a file with the given name.

The file will be created if it not exists and override all previously created content.

Parameters
filenameThe name of the file.
formatThe output format to use when writing into the file.
Returns
True if writing was successfully.

Member Data Documentation

std::atomic_uint16_t ee::Log::SuspendLoggingCounter
staticprivate

This boolean variable can be set to true to suspend logging for a short time period.

Necessary for preventing the generation of log entries during the execution of a callback and possible reset().


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