Belle II Software development
|
Class for logging debug, info and error messages. More...
#include <LogSystem.h>
Public Member Functions | |
void | addLogConnection (LogConnectionBase *logConnection) |
Adds a log connection object which is used to the send the logging messages. | |
void | resetLogConnections () |
Removes all log connections. | |
void | resetLogging () |
Reset logging system to defaults: empty all log messages and reset connections to the default. | |
LogConfig * | getLogConfig () |
Returns global log system configuration. | |
void | addPackageLogConfig (const std::string &package, const LogConfig &logConfig) |
Add the per package log configuration. | |
LogConfig & | getPackageLogConfig (const std::string &package) |
Get the log configuration for the package with the given name. | |
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. | |
bool | sendMessage (LogMessage &&message) |
Sends a log message using the log connection object. | |
void | resetMessageCounter () |
Resets the message counter and error log by setting all message counts to 0. | |
int | getMessageCounter (LogConfig::ELogLevel logLevel) const |
Returns the number of logging calls per log level. | |
const LogConfig & | getCurrentLogConfig (const char *package=nullptr) const |
Returns the current LogConfig object used by the logging system. | |
LogConfig::ELogLevel | getCurrentLogLevel (const char *package=nullptr) const |
Returns the current log level used by the logging system. | |
int | getCurrentDebugLevel (const char *package=nullptr) const |
Returns the current debug level used by the logging system. | |
unsigned | getMaxMessageRepetitions () const |
Get maximum number of repetitions before silencing "identical" log messages. | |
void | setMaxMessageRepetitions (unsigned repetitions) |
Set maximum number of repetitions before silencing "identical" log messages. | |
void | printErrorSummary () |
Print error/warning summary at end of execution. | |
void | enableErrorSummary (bool on) |
enable/disable error/warning summary after successful execution and B2FATAL. | |
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 should only be called by the EventProcessor. | |
Static Public Member Functions | |
static LogSystem & | Instance () |
Static method to get a reference to the LogSystem instance. | |
static void | enableDebug () |
Enable debug output. | |
static bool | debugEnabled () |
Is debug output enabled? | |
Static Public Attributes | |
static const unsigned int | c_errorSummaryMaxLines = 10000 |
Error log will contain at most this many lines. | |
Private Member Functions | |
LogSystem () | |
The constructor is hidden to avoid that someone creates an instance of this class. | |
LogSystem (const LogSystem &)=delete | |
Disable/Hide the copy constructor. | |
LogSystem & | operator= (const LogSystem &)=delete |
Disable/Hide the copy assignment operator. | |
~LogSystem () | |
The LogSystem destructor. | |
void | incMessageCounter (LogConfig::ELogLevel logLevel) |
Increases the counter for the called message level by one. | |
bool | deliverMessageToConnections (const LogMessage &msg) |
Do nothing else than to send the message to all connected connections. | |
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. | |
Private Attributes | |
std::vector< LogConnectionBase * > | m_logConnections |
Stores the pointers to the log connection objects. | |
LogConfig | m_logConfig |
The global log system configuration. | |
const LogConfig * | m_moduleLogConfig |
log config of current module | |
std::string | m_moduleName |
The current module name. | |
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. | |
std::unordered_map< LogMessage, int, LogMessage::TextHasher, LogMessage::TextHasher > | m_messageLog {100} |
Count of previous log messages for the summary and to suppress repetitive messages. | |
unsigned int | m_maxErrorRepetition {0} |
Maximum number to show the same message. | |
unsigned int | m_suppressedMessages {0} |
The amount of messages we have suppressed so far just to get an indication we print this from time to time. | |
int | m_messageCounter [LogConfig::c_Default] |
Counts the number of messages sent per message level. | |
Static Private Attributes | |
static bool | s_debugEnabled = false |
Global flag for fast checking if debug output is enabled. | |
Class for logging debug, info and error messages.
For log messages the following preprocessor macros should be used: B2DEBUG for code development B2INFO for informational messages, e.g. about opened files, processed events, etc. B2RESULT for informational summary messages, e.g. about number of selected events B2WARNING for potential problems that the user should pay attention to B2ERROR for things that went wrong and have to be fixed B2FATAL for situations were the program execution can not be continued
By default the Logger sends messages to std::cout.
Using preprocessor macros has two advantages.
This class is designed as a singleton.
Definition at line 46 of file LogSystem.h.
|
private |
The constructor is hidden to avoid that someone creates an instance of this class.
Definition at line 171 of file LogSystem.cc.
|
private |
The LogSystem destructor.
Definition at line 292 of file LogSystem.cc.
void addLogConnection | ( | LogConnectionBase * | logConnection | ) |
Adds a log connection object which is used to the send the logging messages.
logConnection | Pointer to the logging connection object. The LogSystem takes ownership of this object. |
Definition at line 38 of file LogSystem.cc.
|
inline |
Add the per package log configuration.
Adds a new log configuration for the given package name.
package | The name of the package whose log configuration should be added. |
logConfig | The log configuration which should be assigned to the given package. |
Definition at line 87 of file LogSystem.h.
|
inlinestatic |
Is debug output enabled?
Definition at line 201 of file LogSystem.h.
|
private |
Do nothing else than to send the message to all connected connections.
No bookkeeping, just and and be done
Definition at line 53 of file LogSystem.cc.
|
inlinestatic |
|
inline |
enable/disable error/warning summary after successful execution and B2FATAL.
During normal basf2 execution, this is turned on by the Framework object. For unit tests (i.e. without a Framework object), the default is used instead (off).
Definition at line 181 of file LogSystem.h.
|
inline |
Returns the current debug level used by the logging system.
Definition at line 153 of file LogSystem.h.
|
inline |
Returns the current log level used by the logging system.
Definition at line 146 of file LogSystem.h.
|
inline |
|
inline |
Get maximum number of repetitions before silencing "identical" log messages.
Identity only checks for log level and message content (excluding variables)
Definition at line 160 of file LogSystem.h.
int getMessageCounter | ( | LogConfig::ELogLevel | logLevel | ) | const |
Returns the number of logging calls per log level.
logLevel | The logging level which should be returned. |
Definition at line 161 of file LogSystem.cc.
|
inline |
Get the log configuration for the package with the given name.
If no package specific configuration exists a new one is created.
package | The name of the package whose log configuration should be returned |
Definition at line 96 of file LogSystem.h.
|
private |
Increases the counter for the called message level by one.
logLevel | The logging level which should be increased by one. |
Definition at line 297 of file LogSystem.cc.
|
static |
Static method to get a reference to the LogSystem instance.
Definition at line 31 of file LogSystem.cc.
void printErrorSummary | ( | ) |
Print error/warning summary at end of execution.
Does nothing if m_printErrorSummary is false.
Definition at line 206 of file LogSystem.cc.
void resetLogConnections | ( | ) |
Removes all log connections.
Definition at line 44 of file LogSystem.cc.
void resetLogging | ( | ) |
Reset logging system to defaults: empty all log messages and reset connections to the default.
Definition at line 180 of file LogSystem.cc.
void resetMessageCounter | ( | ) |
Resets the message counter and error log by setting all message counts to 0.
Definition at line 150 of file LogSystem.cc.
bool sendMessage | ( | LogMessage && | message | ) |
Sends a log message using the log connection object.
This method should only be called by the logger macros.
message | The log message object. The message might be moved into internal storage and is not valid any more after the method call. |
Definition at line 69 of file LogSystem.cc.
|
inline |
Set maximum number of repetitions before silencing "identical" log messages.
Identity only checks for log level and message content (excluding variables)
Definition at line 167 of file LogSystem.h.
|
private |
Send a custom message which looks like a log message but should not be counted as such.
This is used in a few places to emit descriptive messages related to other messages without danger of being suppressed
Definition at line 62 of file LogSystem.cc.
|
inline |
Sets the log configuration to the given module log configuration and sets the module name This method should only be called by the EventProcessor.
moduleLogConfig | Pointer to the logging configuration object of the module. Set to NULL to use the global log configuration. |
moduleName | Name of the module. |
Definition at line 191 of file LogSystem.h.
|
static |
Error log will contain at most this many lines.
Definition at line 48 of file LogSystem.h.
|
private |
The global log system configuration.
Definition at line 207 of file LogSystem.h.
|
private |
Stores the pointers to the log connection objects.
(owned by us)
Definition at line 205 of file LogSystem.h.
|
private |
Maximum number to show the same message.
If zero we don't suppress repeated messages
Definition at line 219 of file LogSystem.h.
|
private |
Counts the number of messages sent per message level.
Definition at line 223 of file LogSystem.h.
|
private |
Count of previous log messages for the summary and to suppress repetitive messages.
Definition at line 217 of file LogSystem.h.
|
private |
log config of current module
Definition at line 209 of file LogSystem.h.
|
private |
The current module name.
Definition at line 211 of file LogSystem.h.
|
private |
Stores the log configuration objects for packages.
Definition at line 213 of file LogSystem.h.
|
private |
Wether to re-print errors-warnings encountered during execution at the end.
Definition at line 215 of file LogSystem.h.
|
private |
The amount of messages we have suppressed so far just to get an indication we print this from time to time.
Definition at line 221 of file LogSystem.h.
|
staticprivate |
Global flag for fast checking if debug output is enabled.
Definition at line 225 of file LogSystem.h.