1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-05 01:43:31 +03:00

fixed so that last repeats are printed first with correct time if another message comes

decided for fixed size buffers in LogHandler repeated messages
This commit is contained in:
tomas@poseidon.ndb.mysql.com
2004-12-22 22:47:56 +01:00
parent e9c0a17cf2
commit 263832da65
5 changed files with 47 additions and 47 deletions

View File

@@ -23,21 +23,18 @@
//
LogHandler::LogHandler() :
m_pDateTimeFormat("%d-%.2d-%.2d %.2d:%.2d:%.2d"),
m_errorCode(0),
m_last_category(m_last_category_buf),
m_last_message(m_last_message_buf)
m_errorCode(0)
{
m_max_repeat_frequency= 3; // repeat messages maximum every 3 seconds
m_last_category_buf[0]= 0;
m_last_message_buf[0]= 0;
m_count_repeated_messages= 0;
m_last_category[0]= 0;
m_last_message[0]= 0;
m_last_log_time= 0;
m_now= 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
@@ -51,42 +48,44 @@ LogHandler::append(const char* pCategory, Logger::LoggerLevel 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;
if (m_count_repeated_messages > 0) // print that message
append_impl(m_last_category, m_last_level, m_last_message);
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
strncpy(m_last_category, pCategory, sizeof(m_last_category));
strncpy(m_last_message, pMsg, sizeof(m_last_message));
}
else // repeated message
{
if (now < m_last_log_time+m_max_repeat_frequency)
{
m_count_repeated_messages++;
m_now= now;
return;
}
}
m_now= now;
append_impl(pCategory, level, pMsg);
m_last_log_time= now;
}
void
LogHandler::append_impl(const char* pCategory, Logger::LoggerLevel level,
const char* pMsg)
{
writeHeader(pCategory, level);
if (m_count_repeated_messages == 0)
writeMessage(pMsg);
else
{
BaseString str(pMsg);
str.appfmt(" - repeated %d times", m_count_repeated_messages);
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*
@@ -125,12 +124,10 @@ char*
LogHandler::getTimeAsString(char* pStr) const
{
struct tm* tm_now;
time_t now;
now = ::time((time_t*)NULL);
#ifdef NDB_WIN32
tm_now = localtime(&now);
tm_now = localtime(&m_now);
#else
tm_now = ::localtime(&now); //uses the "current" timezone
tm_now = ::localtime(&m_now); //uses the "current" timezone
#endif
BaseString::snprintf(pStr, MAX_DATE_TIME_HEADER_LENGTH,