11#include <framework/logging/LogConfig.h>
12#include <framework/logging/LogMessage.h>
17#include <unordered_map>
25 class LogConnectionBase;
217 std::unordered_map<LogMessage, int, LogMessage::TextHasher, LogMessage::TextHasher>
m_messageLog{100};
282 return logLevelLimit <= level && (level !=
LogConfig::c_Debug || debugLevelLimit >= debugLevel);
int getDebugLevel() const
Returns the configured debug messaging level.
ELogLevel getLogLevel() const
Returns the configured log level.
ELogLevel
Definition of the supported log levels.
@ c_Debug
Debug: for code development.
@ c_Default
Default: use globally configured log level.
@ c_Message
Log message text.
Abstract base class for the different types of log connections.
Class for logging debug, info and error messages.
unsigned int m_maxErrorRepetition
Maximum number to show the same message.
static bool s_debugEnabled
Global flag for fast checking if debug output is enabled.
unsigned int m_suppressedMessages
The amount of messages we have suppressed so far just to get an indication we print this from time to...
~LogSystem()
The LogSystem destructor.
LogConfig::ELogLevel getCurrentLogLevel(const char *package=nullptr) const
Returns the current log level used by the logging system.
void resetLogging()
Reset logging system to defaults: empty all log messages and reset connections to the default.
void updateModule(const LogConfig *moduleLogConfig=nullptr, const std::string &moduleName="")
Sets the log configuration to the given module log configuration and sets the module name This method...
void addPackageLogConfig(const std::string &package, const LogConfig &logConfig)
Add the per package log configuration.
std::vector< LogConnectionBase * > m_logConnections
Stores the pointers to the log connection objects.
void printErrorSummary()
Print error/warning summary at end of execution.
bool deliverMessageToConnections(const LogMessage &msg)
Do nothing else than to send the message to all connected connections.
int m_messageCounter[LogConfig::c_Default]
Counts the number of messages sent per message level.
LogSystem & operator=(const LogSystem &)=delete
Disable/Hide the copy assignment operator.
void resetMessageCounter()
Resets the message counter and error log by setting all message counts to 0.
std::unordered_map< LogMessage, int, LogMessage::TextHasher, LogMessage::TextHasher > m_messageLog
Count of previous log messages for the summary and to suppress repetitive messages.
std::map< std::string, LogConfig > m_packageLogConfigs
Stores the log configuration objects for packages.
bool m_printErrorSummary
Wether to re-print errors-warnings encountered during execution at the end.
LogConfig * getLogConfig()
Returns global log system configuration.
void enableErrorSummary(bool on)
enable/disable error/warning summary after successful execution and B2FATAL.
bool sendMessage(LogMessage &&message)
Sends a log message using the log connection object.
LogSystem()
The constructor is hidden to avoid that someone creates an instance of this class.
void incMessageCounter(LogConfig::ELogLevel logLevel)
Increases the counter for the called message level by one.
void setMaxMessageRepetitions(unsigned repetitions)
Set maximum number of repetitions before silencing "identical" log messages.
LogConfig m_logConfig
The global log system configuration.
int getCurrentDebugLevel(const char *package=nullptr) const
Returns the current debug level used by the logging system.
const LogConfig * m_moduleLogConfig
log config of current module
std::string m_moduleName
The current module name.
int getMessageCounter(LogConfig::ELogLevel logLevel) const
Returns the number of logging calls per log level.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
static const unsigned int c_errorSummaryMaxLines
Error log will contain at most this many lines.
static void enableDebug()
Enable debug output.
void resetLogConnections()
Removes all log connections.
unsigned getMaxMessageRepetitions() const
Get maximum number of repetitions before silencing "identical" log messages.
LogConfig & getPackageLogConfig(const std::string &package)
Get the log configuration for the package with the given name.
void showText(LogConfig::ELogLevel level, const std::string &txt, int info=LogConfig::c_Message)
Send a custom message which looks like a log message but should not be counted as such.
static bool debugEnabled()
Is debug output enabled?
LogSystem(const LogSystem &)=delete
Disable/Hide the copy constructor.
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
const LogConfig & getCurrentLogConfig(const char *package=nullptr) const
Returns the current LogConfig object used by the logging system.
bool isLevelEnabled(LogConfig::ELogLevel level, int debugLevel=0, const char *package=nullptr) const
Returns true if the given log level is allowed by the log system (i.e.
Abstract base class for different kinds of events.