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>
55 bool messageSent =
false;
57 messageSent |= con->sendMessage(message);
64 LogMessage customText(level, txt,
"",
"",
"", 0);
73 if ((packageLogConfig !=
m_packageLogConfigs.end()) && packageLogConfig->second.getLogInfo(logLevel)) {
74 message.setLogInfo(packageLogConfig->second.getLogInfo(logLevel));
88 unsigned int repetition{0};
93 repetition = ++(it->second);
99 message.setCount(repetition);
124 connection->finalizeOnAbort();
131 signal(SIGSEGV,
nullptr);
139 if (messageSent and lastTime) {
142 " times and will be suppressed in future",
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.
ELogLevel getAbortLevel() const
Returns the configured abort 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.
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.
void resetLogging()
Reset logging system to defaults: empty all log messages and reset connections to the default.
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.
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
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.
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.