Add log widget to lower dock
[frida/frida.git] / src / gui / widgets / LogDockAppender.cxx
1 #include "LogDockAppender.hxx"
2 #include "LogDock.hxx"
3
4 #include <log4cxx/patternlayout.h>
5
6 using namespace log4cxx::helpers;
7
8 IMPLEMENT_LOG4CXX_OBJECT(LogDockAppender)
9
10 LogDockAppender::LogDockAppender()
11 : timeformat("%T") {
12 layout = new PatternLayout("%d{MMM dd yyyy HH:mm:ss,SSS} - %m %n");
13 }
14
15 void LogDockAppender::append(const spi::LoggingEventPtr& event, Pool& p) {
16 log4cxx::LogString message, timestamp;
17
18 if ( this->layout == NULL ) {
19 LOG4CXX_ENCODE_CHAR(nameStr, name);
20 std::string msg("No Layout set for the appender named [ ");
21 msg.append(nameStr);
22 msg.append(" ].");
23
24 LOG4CXX_DECODE_CHAR(msgL, msg);
25 errorHandler->error(msgL);
26 return;
27 }
28
29 layout->format(message, event, p);
30 timeformat.format(timestamp, event->getTimeStamp(), p);
31 LOG4CXX_ENCODE_CHAR(messageencode, message);
32 LOG4CXX_ENCODE_CHAR(timestampencode, timestamp);
33
34 int rowcount = target->rowCount();
35 target->insertRow(rowcount);
36 target->setItem(rowcount, 0, new QTableWidgetItem(timestampencode.c_str()));
37 target->setItem(rowcount, 1, new QTableWidgetItem(event->getLevel()->toString().c_str()));
38 target->setItem(rowcount, 2, new QTableWidgetItem(messageencode.c_str()));
39 target->resizeColumnsToContents();
40 }
41
42 void LogDockAppender::setTarget(LogDock *target) {
43 this->target = target;
44 }
45
46 void LogDockAppender::close() {
47
48 }
49
50 bool LogDockAppender::requiresLayout() const {
51 return true;
52 }