horizontalHeader()->setStretchLastSection(true);
verticalHeader()->setDefaultSectionSize(18);
appender = new LogDockAppender;
- appender->setTarget(this);
+ connect(appender, &LogDockAppender::newLogEntry,
+ this, &LogDock::handleNewLogEntry);
log4cxx::BasicConfigurator::configure(appender);
}
LogDock::~LogDock() {
delete appender;
}
+
+void LogDock::handleNewLogEntry(QColor color, QString timestamp, QString level, QString message) {
+ int rowcount = rowCount();
+ insertRow(rowcount);
+ setItem(rowcount, 0, new QTableWidgetItem(timestamp));
+ setItem(rowcount, 1, new QTableWidgetItem(level));
+ setItem(rowcount, 2, new QTableWidgetItem(message));
+ item(rowcount, 0)->setBackground(color);
+ item(rowcount, 1)->setBackground(color);
+ item(rowcount, 2)->setBackground(color);
+ resizeColumnsToContents();
+
+ QTimer *timer = new QTimer(this);
+ timer->setSingleShot(true);
+
+ QObject::connect(timer, &QTimer::timeout, [=]() {
+ scrollToItem(item(rowcount, 2), QAbstractItemView::PositionAtTop);
+ });
+ timer->start(2);
+}
log4cxx::Appender* getAppender();
private:
LogDockAppender* appender;
+ void handleNewLogEntry(QColor color, QString timestamp, QString level, QString message);
friend class LogDockAppender;
};
} else if (log4cxx::Level::getTrace() == event->getLevel()) {
rowcolor.setRgb(0xee, 0xff, 0xee);
}
-
- int rowcount = target->rowCount();
- target->insertRow(rowcount);
- target->setItem(rowcount, 0, new QTableWidgetItem(timestampencode.c_str()));
- target->setItem(rowcount, 1, new QTableWidgetItem(event->getLevel()->toString().c_str()));
- target->setItem(rowcount, 2, new QTableWidgetItem(messageencode.c_str()));
- target->item(rowcount, 0)->setBackground(rowcolor);
- target->item(rowcount, 1)->setBackground(rowcolor);
- target->item(rowcount, 2)->setBackground(rowcolor);
- target->resizeColumnsToContents();
-
- QTimer *timer = new QTimer(target);
- timer->setSingleShot(true);
-
- QObject::connect(timer, &QTimer::timeout, [=]() {
- target->scrollToItem(target->item(rowcount, 2), QAbstractItemView::PositionAtTop);
- });
- timer->start(10);
-}
-
-void LogDockAppender::setTarget(LogDock *target) {
- this->target = target;
+ emit newLogEntry(rowcolor, timestampencode.c_str(),
+ event->getLevel()->toString().c_str(),
+ messageencode.c_str());
}
void LogDockAppender::close() {
#include <log4cxx/appenderskeleton.h>
#include <log4cxx/spi/loggingevent.h>
#include <log4cxx/helpers/strftimedateformat.h>
+#include <QObject>
class LogDock;
using namespace log4cxx;
-class LogDockAppender : public AppenderSkeleton {
+class LogDockAppender : public QObject, public AppenderSkeleton {
+ Q_OBJECT
+signals:
+ void newLogEntry(QColor color, QString timestamp, QString level, QString message);
public:
LogDockAppender();
- void setTarget(LogDock* target);
void append(const spi::LoggingEventPtr& event, helpers::Pool& p);
void close();
bool requiresLayout() const;
LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
END_LOG4CXX_CAST_MAP()
private:
- LogDock* target;
helpers::StrftimeDateFormat timeformat;
};