From 2e68bac77646678c1e0fb0ddfcdeb4d847b3265e Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 19 May 2015 19:55:35 +0200 Subject: [PATCH] Color logmessages according to severity Closes T12 --- src/gui/widgets/LogDockAppender.cxx | 58 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/gui/widgets/LogDockAppender.cxx b/src/gui/widgets/LogDockAppender.cxx index f6419c2..5003139 100644 --- a/src/gui/widgets/LogDockAppender.cxx +++ b/src/gui/widgets/LogDockAppender.cxx @@ -15,28 +15,42 @@ LogDockAppender::LogDockAppender() void LogDockAppender::append(const spi::LoggingEventPtr& event, Pool& p) { log4cxx::LogString message, timestamp; - if ( this->layout == NULL ) { - LOG4CXX_ENCODE_CHAR(nameStr, name); - std::string msg("No Layout set for the appender named [ "); - msg.append(nameStr); - msg.append(" ]."); - - LOG4CXX_DECODE_CHAR(msgL, msg); - errorHandler->error(msgL); - return; - } - - layout->format(message, event, p); - timeformat.format(timestamp, event->getTimeStamp(), p); - LOG4CXX_ENCODE_CHAR(messageencode, message); - LOG4CXX_ENCODE_CHAR(timestampencode, timestamp); - - 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->resizeColumnsToContents(); + if ( this->layout == NULL ) { + LOG4CXX_ENCODE_CHAR(nameStr, name); + std::string msg("No Layout set for the appender named [ "); + msg.append(nameStr); + msg.append(" ]."); + + LOG4CXX_DECODE_CHAR(msgL, msg); + errorHandler->error(msgL); + return; + } + + layout->format(message, event, p); + timeformat.format(timestamp, event->getTimeStamp(), p); + LOG4CXX_ENCODE_CHAR(messageencode, message); + LOG4CXX_ENCODE_CHAR(timestampencode, timestamp); + + QColor rowcolor(0xff, 0xff, 0xff, 0xff); + if (log4cxx::Level::getFatal() == event->getLevel()) { + rowcolor.setRgb(0xff, 0x00, 0x22); + } else if (log4cxx::Level::getError() == event->getLevel()) { + rowcolor.setRgb(0xff, 0x00, 0x00); + } else if (log4cxx::Level::getWarn() == event->getLevel()) { + rowcolor.setRgb(0x00, 0xff, 0xff); + } 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(); } void LogDockAppender::setTarget(LogDock *target) { -- 2.39.5