Added truncating to IPC log buffer queue #4651

When the IPC log buffer is too large, the oldest log line is removed
when a new log line is added.
This commit is contained in:
Nick Bolton 2015-05-15 15:04:16 +01:00
parent aac59fbf7e
commit e60b3a6feb
2 changed files with 9 additions and 4 deletions

View File

@ -116,7 +116,12 @@ void
IpcLogOutputter::appendBuffer(const String& text) IpcLogOutputter::appendBuffer(const String& text)
{ {
ArchMutexLock lock(m_bufferMutex); ArchMutexLock lock(m_bufferMutex);
m_buffer.push(text); if (m_buffer.size() >= m_bufferMaxSize) {
// if the queue is exceeds size limit,
// throw away the oldest item
m_buffer.pop_front();
}
m_buffer.push_back(text);
} }
void void
@ -182,7 +187,7 @@ IpcLogOutputter::getChunk(size_t count)
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
chunk.append(m_buffer.front()); chunk.append(m_buffer.front());
chunk.append("\n"); chunk.append("\n");
m_buffer.pop(); m_buffer.pop_front();
} }
return chunk; return chunk;
} }

View File

@ -22,7 +22,7 @@
#include "arch/IArchMultithread.h" #include "arch/IArchMultithread.h"
#include "base/ILogOutputter.h" #include "base/ILogOutputter.h"
#include <queue> #include <deque>
class IpcServer; class IpcServer;
class Event; class Event;
@ -87,7 +87,7 @@ private:
void appendBuffer(const String& text); void appendBuffer(const String& text);
private: private:
typedef std::queue<String> Buffer; typedef std::deque<String> Buffer;
IpcServer& m_ipcServer; IpcServer& m_ipcServer;
Buffer m_buffer; Buffer m_buffer;