summaryrefslogtreecommitdiff
path: root/ndb/src/common/logger/LogHandler.cpp
diff options
context:
space:
mode:
authorunknown <tomas@poseidon.ndb.mysql.com>2004-12-22 18:27:07 +0100
committerunknown <tomas@poseidon.ndb.mysql.com>2004-12-22 18:27:07 +0100
commiteebd8d7e41fbfc954b567ac6561a5b3b617a232e (patch)
tree1c02eae040951ff28b473030c10b96caa18d7cf7 /ndb/src/common/logger/LogHandler.cpp
parentc3cb363d6de59617924c0372acc35f3476dd775b (diff)
downloadmariadb-git-eebd8d7e41fbfc954b567ac6561a5b3b617a232e.tar.gz
added handling of repeated messages
ndb/src/common/transporter/Transporter.hpp: fixed small error
Diffstat (limited to 'ndb/src/common/logger/LogHandler.cpp')
-rw-r--r--ndb/src/common/logger/LogHandler.cpp59
1 files changed, 54 insertions, 5 deletions
diff --git a/ndb/src/common/logger/LogHandler.cpp b/ndb/src/common/logger/LogHandler.cpp
index a76cb622878..5cc8de21f67 100644
--- a/ndb/src/common/logger/LogHandler.cpp
+++ b/ndb/src/common/logger/LogHandler.cpp
@@ -23,22 +23,71 @@
//
LogHandler::LogHandler() :
m_pDateTimeFormat("%d-%.2d-%.2d %.2d:%.2d:%.2d"),
- m_errorCode(0)
-{
+ m_errorCode(0),
+ m_last_category(m_last_category_buf),
+ m_last_message(m_last_message_buf)
+{
+ m_max_repeat_frequency= 3; // repeat messages maximum every 3 seconds
+ m_last_category_buf[0]= 0;
+ m_last_message_buf[0]= 0;
}
LogHandler::~LogHandler()
{
+ if (m_last_message != m_last_message_buf)
+ free(m_last_message);
+ if (m_last_category != m_last_category_buf)
+ free(m_last_category);
}
void
LogHandler::append(const char* pCategory, Logger::LoggerLevel level,
const char* pMsg)
-{
+{
+ time_t now;
+ now= ::time((time_t*)NULL);
+
+ if (level != m_last_level ||
+ strcmp(pCategory, m_last_category) ||
+ strcmp(pMsg, m_last_message))
+ {
+ if (m_last_message != m_last_message_buf)
+ free(m_last_message);
+ if (m_last_category != m_last_category_buf)
+ free(m_last_category);
+
+ m_count_repeated_messages= 0;
+
+ m_last_level= level;
+ BaseString::snprintf(m_last_category_buf, sizeof(m_last_category_buf), "%s", pCategory);
+ BaseString::snprintf(m_last_message_buf, sizeof(m_last_message_buf), "%s", pMsg);
+ // ToDo: handle too long messages correctly
+ // right now all that will happen is that too long messages
+ // will be repeated unneccesarily
+ }
+ else // repeated message
+ {
+ if (now < m_last_log_time+m_max_repeat_frequency)
+ {
+ m_count_repeated_messages++;
+ return;
+ }
+ }
+
writeHeader(pCategory, level);
- writeMessage(pMsg);
+ if (m_count_repeated_messages == 0)
+ writeMessage(pMsg);
+ else
+ {
+ BaseString str(pMsg);
+ str.appfmt(" - repeated %d times", m_count_repeated_messages);
+ writeMessage(str.c_str());
+ m_count_repeated_messages= 0;
+ }
writeFooter();
-}
+
+ m_last_log_time= now;
+}
const char*
LogHandler::getDefaultHeader(char* pStr, const char* pCategory,