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>
19#include <unordered_map>
52 bool messageSent =
false;
54 messageSent |= con->sendMessage(message);
61 LogMessage customText(level, txt,
"",
"",
"", 0);
70 if ((packageLogConfig !=
m_packageLogConfigs.end()) && packageLogConfig->second.getLogInfo(logLevel)) {
71 message.setLogInfo(packageLogConfig->second.getLogInfo(logLevel));
75 message.setLogInfo(
m_logConfig.getLogInfo(logLevel));
85 unsigned int repetition{0};
90 repetition = ++(it->second);
96 message.setCount(repetition);
121 connection->finalizeOnAbort();
128 signal(SIGSEGV,
nullptr);
136 if (messageSent and lastTime) {
139 " times and will be suppressed in future",
212 std::vector<std::pair<LogMessage, unsigned int>> messages;
215 messages.emplace_back(std::move(value));
218 std::stable_sort(messages.begin(), messages.end(), [](
const auto & a,
const auto & b) {
219 return a.first.getLogLevel() > b.first.getLogLevel() or
220 (a.first.getLogLevel() == b.first.getLogLevel() and a.second > b.second);
222 if (messages.size() == 0) {
229 const LogConfig* oldModuleConfig {
nullptr};
232 map<string, LogConfig> oldPackageConfig;
249 for (
auto & [msg, count] : messages) {
250 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.
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.
@ 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.
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.
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
Whether 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.