Commit 366239e6 authored by grunau's avatar grunau
Browse files

BufferingLog: store log messages in memory

BufferingLog is a tgt::Log subclass that stores log messages in
a bounded deque, whose maximum size is specified when calling
BufferingLog's constructor. When it reaches its maximum capacity and is
asked to store additional messages, it discards old ones according to
the least recently used policy.

There will soon be a Qt model using BufferingLog as its data source.
It will provide log filtering and message formatting.

git-svn-id: https://camplinux.in.tum.de/svn/campvis/branches/gui-redux@508 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 3121761e
......@@ -48,6 +48,7 @@ SET(CampvisApplicationToBeMocced
gui/properties/stringpropertywidget.h
gui/properties/transferfunctionpropertywidget.h
tools/qtexteditlog.h
tools/bufferinglog.h
)
LIST(APPEND CampvisApplicationDefinitions "-DCAMPVIS_SOURCE_DIR=\"${CampvisHome}\"")
......
#include "bufferinglog.h"
#include "tgt/assert.h"
namespace campvis {
BufferingLog::BufferingLog(unsigned int maxSize, QObject* parent, bool dateStamping,
bool timeStamping, bool showCat, bool showLevel)
: QObject(parent)
{
_maxSize = maxSize;
dateStamping_ = dateStamping;
timeStamping_ = timeStamping;
showCat_ = showCat;
showLevel_ = showLevel;
}
void BufferingLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg,
const std::string& /*extendedInfo*/)
{
std::string output = "";
if (dateStamping_)
output += "[" + getDateString() + "] ";
if (timeStamping_)
output += "[" + getTimeString() + "] ";
if (showCat_)
output += cat + " ";
if (showLevel_)
output += "(" + getLevelString(level) + ") ";
if (output != "")
output += '\t';
output += msg;
{
tbb::mutex::scoped_lock lock(_localMutex);
_buffer.push_back(output);
if (_buffer.size() > _maxSize) {
_buffer.pop_front();
}
}
emit s_messageAppended(QString::fromStdString(output));
}
}
#ifndef BUFFERINGLOG_H__
#define BUFFERINGLOG_H__
#include "tbb/mutex.h"
#include "tgt/logmanager.h"
#include <deque>
#include <QObject>
using namespace tgt;
namespace campvis {
/**
* BufferingLog stores up to the specified number of messages in memory.
*/
class BufferingLog : public QObject, public Log {
Q_OBJECT
public:
/**
* Creates a new BufferingLog.
*
* When the BufferingLog reaches its maximum capacity and is asked to store
* additional messages, it discards old ones according to the least recently
* used policy.
*
* \param maxSize the maximum number of messages this log should store
* \param dateStamping should logged messages be date-stamped
* \param timeStamping should logged messages be time-stamped
* \param showCat should the category be printed along with the messages
* \param showLevel should the LogLevel be printed along with the messages
*/
BufferingLog(unsigned int maxSize, QObject* parent = 0, bool dateStamping = true,
bool timeStamping = true, bool showCat = true, bool showLevel = true);
virtual ~BufferingLog() {}
bool isOpen() { return true; }
signals:
/**
* Signal invoked when a new message has been appended to the log.
*
* \param message the new log message
*/
void s_messageAppended(const QString& message);
protected:
unsigned int _maxSize;
tbb::mutex _localMutex;
std::deque<std::string> _buffer;
void logFiltered(const std::string &cat, LogLevel level, const std::string& msg, const std::string& extendedInfo="");
};
}
#endif // BUFFERINGLOG_H__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment