9 #include <framework/logging/LogSystem.h> 
   10 #include <framework/logging/LogMessage.h> 
   11 #include <framework/logging/LogConnectionBase.h> 
   12 #include <framework/logging/LogConnectionFilter.h> 
   13 #include <framework/logging/LogConnectionConsole.h> 
   14 #include <framework/datastore/DataStore.h> 
   21 #include <unordered_map> 
   40   m_logConnections.push_back(logConnection);
 
   46   for (
auto connection : m_logConnections) {
 
   49   m_logConnections.clear();
 
   55   bool messageSent = 
false;
 
   56   for (
auto con : m_logConnections) {
 
   57     messageSent |= con->sendMessage(message);
 
   64   LogMessage customText(level, txt, 
"", 
"", 
"", 0);
 
   66   deliverMessageToConnections(customText);
 
   72   auto packageLogConfig = m_packageLogConfigs.find(message.getPackage());
 
   73   if ((packageLogConfig != m_packageLogConfigs.end()) && packageLogConfig->second.getLogInfo(logLevel)) {
 
   74     message.setLogInfo(packageLogConfig->second.getLogInfo(logLevel));
 
   75   } 
else if (m_moduleLogConfig && m_moduleLogConfig->getLogInfo(logLevel)) {
 
   76     message.setLogInfo(m_moduleLogConfig->getLogInfo(logLevel));
 
   78     message.setLogInfo(m_logConfig.getLogInfo(logLevel));
 
   81   message.setModule(m_moduleName);
 
   84   incMessageCounter(logLevel);
 
   88   unsigned int repetition{0};
 
   89   if (m_messageLog.size() >= c_errorSummaryMaxLines) {
 
   92     if (
auto it = m_messageLog.find(message); it != m_messageLog.end()) {
 
   93       repetition = ++(it->second);
 
   98     repetition = ++m_messageLog[message];
 
   99     message.setCount(repetition);
 
  101   lastTime = m_maxErrorRepetition > 0 and repetition == m_maxErrorRepetition;
 
  102   if (m_maxErrorRepetition > 0 and repetition > m_maxErrorRepetition) {
 
  105     ++m_suppressedMessages;
 
  109     if ((m_suppressedMessages < 1000 and m_suppressedMessages % 100 == 0) or
 
  110         (m_suppressedMessages < 10000 and m_suppressedMessages % 1000 == 0) or
 
  111         (m_suppressedMessages % 10000 == 0)) {
 
  112       showText(
LogConfig::c_Warning, 
"... " + std::to_string(m_suppressedMessages) + 
" log messages suppressed due to repetition ...");
 
  118   bool messageSent = deliverMessageToConnections(message);
 
  120   if (logLevel >= m_logConfig.getAbortLevel()) {
 
  123     for (
auto connection : m_logConnections) {
 
  124       connection->finalizeOnAbort();
 
  131     signal(SIGSEGV, 
nullptr);
 
  139   if (messageSent and lastTime) {
 
  141              "The previous message has occurred " + std::to_string(m_maxErrorRepetition) +
 
  142              " times and will be suppressed in future",
 
  152   for (
int& i : m_messageCounter) {
 
  155   m_suppressedMessages = 0;
 
  156   m_messageLog.clear();
 
  157   m_messageLog.reserve(100);
 
  163   return m_messageCounter[logLevel];
 
  173   m_moduleLogConfig(nullptr),
 
  174   m_printErrorSummary(false),
 
  215   std::vector<std::pair<LogMessage, unsigned int>> messages;
 
  218     messages.emplace_back(std::move(value));
 
  221   std::stable_sort(messages.begin(), messages.end(), [](
const auto & a, 
const auto & b) {
 
  222     return a.first.getLogLevel() > b.first.getLogLevel() or
 
  223            (a.first.getLogLevel() == b.first.getLogLevel() and  a.second > b.second);
 
  225   if (messages.size() == 0) {
 
  232   const LogConfig* oldModuleConfig {
nullptr};
 
  235   map<string, LogConfig> oldPackageConfig;
 
  252   for (
auto & [msg, count] : messages) {
 
  253     const bool multiple = count > 1;
 
static DataStore & Instance()
Instance of singleton Store.
void reset(EDurability durability)
Frees memory occupied by data store items and removes all objects from the map.
void setDebugLevel(int debugLevel)
Configure the debug messaging level.
ELogLevel
Definition of the supported log levels.
@ c_Error
Error: for things that went wrong and have to be fixed.
@ c_Info
Info: for informational messages, e.g.
@ c_Debug
Debug: for code development.
@ c_Fatal
Fatal: for situations were the program execution can not be continued.
@ c_Warning
Warning: for potential problems that the user should pay attention to.
@ c_Result
Result: for informational summary messages, e.g.
@ c_Default
Default: use globally configured log level.
static const int c_DefaultDebugLevel
Default debug level.
unsigned int getLogInfo(ELogLevel logLevel) const
Returns the configured log information for the given level.
void setAbortLevel(ELogLevel abortLevel)
Configure the abort level.
@ c_Module
Module in which the message was emitted.
@ c_File
Source file in which the message was emitted.
@ c_Function
Function in which the message was emitted.
@ c_Line
Line in source file in which the message was emitted.
@ c_Level
Log level of the message.
@ c_Message
Log message text.
@ c_NoVariables
If set don't output any variables that are part of the message.
void setLogLevel(ELogLevel logLevel)
Configure the log level.
void setLogInfo(ELogLevel logLevel, unsigned int logInfo)
Configure the printed log information for the given level.
Abstract base class for the different types of log connections.
Implements a log connection to an IO Stream.
Implements a log connection that filters repeated messages.
void setLogInfo(unsigned int logInfo)
Configure which information should be printed.
Class for logging debug, info and error messages.
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.
void resetLogging()
Reset logging system to defaults: empty all log messages and reset connections to the default.
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.
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.
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.
LogConfig m_logConfig
The global log system configuration.
const LogConfig * m_moduleLogConfig
log config of current module
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.
void resetLogConnections()
Removes all log 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.
void addLogConnection(LogConnectionBase *logConnection)
Adds a log connection object which is used to the send the logging messages.
Abstract base class for different kinds of events.