-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogwidget.cpp
More file actions
41 lines (35 loc) · 1.37 KB
/
logwidget.cpp
File metadata and controls
41 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "logwidget.h"
#include <QtCore/QDateTime>
#include <QtCore/QString>
void QtObjectLogSink::sink(const util::LogMessage& message) {
emit gotMessage(message);
}
LogWidget::LogWidget(QWidget* parent)
: QTreeWidget(parent) {
QtObjectLogSink* sink = new QtObjectLogSink();
util::Logging::getInstance().setSink("__qtobject__", sink);
connect(sink, SIGNAL(gotMessage(util::LogMessage)), this, SLOT(addLogMessage(util::LogMessage)));
/*
LOG(INFO) << "Test info";
LOG(NOTICE) << "Test notice";
LOG(WARNING) << "Test warning";
LOG(ERROR) << "Test error";
LOG(EMERGENCY) << "Holy shit what's happening?!";
*/
}
void LogWidget::addLogMessage(const util::LogMessage& message) {
QTreeWidgetItem* item = new QTreeWidgetItem(this);
item->setText(0, QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
item->setText(1, QString::fromStdString(util::LogLevelHelper::levelToString(message.level)));
item->setText(2, QString::fromStdString(message.logger));
item->setText(3, QString::fromStdString(message.message));
QString icon = "dialog-information";
if (message.level == util::LogLevel::WARNING) {
icon = "dialog-warning";
} else if (message.level <= util::LogLevel::ERROR) {
icon = "dialog-error";
}
item->setIcon(1, QIcon::fromTheme(icon));
addTopLevelItem(item);
scrollToBottom();
}