replace LogDisplay with File logger

- added abstract logger interface
This commit is contained in:
Stojce Slavkovski 2013-12-22 18:56:53 +01:00
parent 3d44ab9939
commit ee1eb25dfa
13 changed files with 150 additions and 59 deletions

View file

@ -12,9 +12,9 @@ QPlainTextEdit {
QLineEdit { QLineEdit {
padding-left: 7px; padding-left: 7px;
background-color: #CCCCCC; background-color: #CCCCCC;
border-width: 0; border-width: 0;
border-top-right-radius: 9px; border-top-right-radius: 9px;
border-bottom-right-radius: 9px; border-bottom-right-radius: 9px;
color: #333333; color: #333333;
font-size: 12px; font-size: 12px;
} }
@ -39,8 +39,8 @@ QPushButton#revealLogButton {
padding-left: 10px; padding-left: 10px;
background-color: #333333; background-color: #333333;
color: #BBBBBB; color: #BBBBBB;
border-width: 0; border-width: 0;
border-radius: 9px; border-radius: 9px;
font-size: 11px; font-size: 11px;
} }

View file

@ -0,0 +1,33 @@
//
// AbstractLoggerInterface.h
// interface
//
// Created by Stojce Slavkovski on 12/22/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__AbstractLoggerInterface__
#define __interface__AbstractLoggerInterface__
#include <QtCore/QObject>
#include <QString>
#include <QStringList>
class AbstractLoggerInterface : public QObject {
Q_OBJECT
public:
inline bool extraDebugging() { return _extraDebugging; };
inline void setExtraDebugging(bool debugging) { _extraDebugging = debugging; };
virtual void addMessage(QString) = 0;
virtual QStringList getLogData(QString) = 0;
signals:
void logReceived(QString message);
private:
bool _extraDebugging = false;
};
#endif /* defined(__hifi__AbstractAudioInterface__) */

View file

@ -88,7 +88,7 @@ const float MIRROR_REARVIEW_BODY_DISTANCE = 1.f;
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) { void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message) {
fprintf(stdout, "%s", message.toLocal8Bit().constData()); fprintf(stdout, "%s", message.toLocal8Bit().constData());
LogDisplay::instance.addMessage(message.toLocal8Bit().constData()); Application::getInstance()->getLogger()->addMessage(message.toLocal8Bit().constData());
} }
Application::Application(int& argc, char** argv, timeval &startup_time) : Application::Application(int& argc, char** argv, timeval &startup_time) :
@ -149,6 +149,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
QFontDatabase::addApplicationFont("resources/styles/Inconsolata.otf"); QFontDatabase::addApplicationFont("resources/styles/Inconsolata.otf");
_window->setWindowTitle("Interface"); _window->setWindowTitle("Interface");
_logger = new FileLogger();
qInstallMessageHandler(messageHandler); qInstallMessageHandler(messageHandler);
// call Menu getInstance static method to set up the menu // call Menu getInstance static method to set up the menu
@ -1346,7 +1348,7 @@ void Application::idle() {
// Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing // Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing
// details if we're in ExtraDebugging mode. However, the ::update() and it's subcomponents will show their timing // details if we're in ExtraDebugging mode. However, the ::update() and it's subcomponents will show their timing
// details normally. // details normally.
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); bool showWarnings = getLogger()->extraDebugging();
PerformanceWarning warn(showWarnings, "Application::idle()"); PerformanceWarning warn(showWarnings, "Application::idle()");
timeval check; timeval check;
@ -2665,7 +2667,7 @@ void Application::queryOctree(NODE_TYPE serverType, PACKET_TYPE packetType, Node
return; return;
} }
bool wantExtraDebugging = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); bool wantExtraDebugging = getLogger()->extraDebugging();
// These will be the same for all servers, so we can set them up once and then reuse for each server we send to. // These will be the same for all servers, so we can set them up once and then reuse for each server we send to.
_voxelQuery.setWantLowResMoving(!Menu::getInstance()->isOptionChecked(MenuOption::DisableLowRes)); _voxelQuery.setWantLowResMoving(!Menu::getInstance()->isOptionChecked(MenuOption::DisableLowRes));
@ -3349,11 +3351,6 @@ void Application::displayOverlay() {
if (Menu::getInstance()->isOptionChecked(MenuOption::CoverageMap)) { if (Menu::getInstance()->isOptionChecked(MenuOption::CoverageMap)) {
renderCoverageMap(); renderCoverageMap();
} }
if (Menu::getInstance()->isOptionChecked(MenuOption::Log)) {
LogDisplay::instance.render(_glWidget->width(), _glWidget->height());
}
// Show chat entry field // Show chat entry field
if (_chatEntryOn) { if (_chatEntryOn) {
@ -4356,7 +4353,7 @@ void* Application::networkReceive(void* args) {
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::networkReceive()... _voxelProcessor.queueReceivedPacket()"); "Application::networkReceive()... _voxelProcessor.queueReceivedPacket()");
bool wantExtraDebugging = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); bool wantExtraDebugging = app->getLogger()->extraDebugging();
if (wantExtraDebugging && app->_incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) { if (wantExtraDebugging && app->_incomingPacket[0] == PACKET_TYPE_VOXEL_DATA) {
int numBytesPacketHeader = numBytesForPacketHeader(app->_incomingPacket); int numBytesPacketHeader = numBytesForPacketHeader(app->_incomingPacket);
unsigned char* dataAt = app->_incomingPacket + numBytesPacketHeader; unsigned char* dataAt = app->_incomingPacket + numBytesPacketHeader;
@ -4481,7 +4478,7 @@ void Application::loadScript() {
void Application::toggleLogDialog() { void Application::toggleLogDialog() {
if (! _logDialog) { if (! _logDialog) {
_logDialog = new LogDialog(_glWidget); _logDialog = new LogDialog(_glWidget, getLogger());
_logDialog->show(); _logDialog->show();
} else { } else {
_logDialog->close(); _logDialog->close();

View file

@ -69,6 +69,7 @@
#include "ui/RearMirrorTools.h" #include "ui/RearMirrorTools.h"
#include "ui/LodToolsDialog.h" #include "ui/LodToolsDialog.h"
#include "ui/LogDialog.h" #include "ui/LogDialog.h"
#include "FileLogger.h"
#include "ParticleTreeRenderer.h" #include "ParticleTreeRenderer.h"
#include "ParticleEditHandle.h" #include "ParticleEditHandle.h"
#include "ControllerScriptingInterface.h" #include "ControllerScriptingInterface.h"
@ -201,7 +202,8 @@ public:
VoxelShader& getVoxelShader() { return _voxelShader; } VoxelShader& getVoxelShader() { return _voxelShader; }
PointShader& getPointShader() { return _pointShader; } PointShader& getPointShader() { return _pointShader; }
FileLogger* getLogger() { return _logger; }
glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); } glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); }
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; } NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; }
@ -509,6 +511,8 @@ private:
std::vector<Avatar*> _avatarFades; std::vector<Avatar*> _avatarFades;
ControllerScriptingInterface _controllerScriptingInterface; ControllerScriptingInterface _controllerScriptingInterface;
QPointer<LogDialog> _logDialog; QPointer<LogDialog> _logDialog;
FileLogger* _logger;
}; };
#endif /* defined(__interface__Application__) */ #endif /* defined(__interface__Application__) */

View file

@ -0,0 +1,38 @@
//
// FileLogger.cpp
// hifi
//
// Created by Stojce Slavkovski on 12/22/13.
//
//
#include "FileLogger.h"
FileLogger::FileLogger() : _lines(NULL) {
setExtraDebugging(false);
}
QStringList FileLogger::getLogData(QString searchText) {
if (searchText.isEmpty()) {
return _lines;
}
// wait for adding new log data while iterating over _lines
// pthread_mutex_lock(& _mutex);
QStringList filteredList;
for (int i = 0; i < _lines.size(); ++i) {
if (_lines[i].contains(searchText, Qt::CaseInsensitive)) {
filteredList.append(_lines[i]);
}
}
// pthread_mutex_unlock(& _mutex);
return filteredList;
}
void FileLogger::addMessage(QString message) {
emit logReceived(message);
_lines.append(message);
// TODO: append message to file
}

View file

@ -0,0 +1,28 @@
//
// FileLogger.h
// hifi
//
// Created by Stojce Slavkovski on 12/22/13.
//
//
#ifndef hifi_FileLogger_h
#define hifi_FileLogger_h
#include "AbstractLoggerInterface.h"
class FileLogger : public AbstractLoggerInterface {
Q_OBJECT
public:
FileLogger();
virtual void addMessage(QString);
virtual QStringList getLogData(QString);
private:
QStringList _lines;
};
#endif

View file

@ -497,8 +497,6 @@ Menu::Menu() :
addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::EchoServerAudio); addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::EchoServerAudio);
addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::EchoLocalAudio); addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::EchoLocalAudio);
addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::ExtraDebugging);
addActionToQMenuAndActionHash(developerMenu, MenuOption::PasteToVoxel, addActionToQMenuAndActionHash(developerMenu, MenuOption::PasteToVoxel,
Qt::CTRL | Qt::SHIFT | Qt::Key_V, Qt::CTRL | Qt::SHIFT | Qt::Key_V,
this, this,

View file

@ -183,7 +183,6 @@ namespace MenuOption {
const QString EchoServerAudio = "Echo Server Audio"; const QString EchoServerAudio = "Echo Server Audio";
const QString EchoLocalAudio = "Echo Local Audio"; const QString EchoLocalAudio = "Echo Local Audio";
const QString ExportVoxels = "Export Voxels"; const QString ExportVoxels = "Export Voxels";
const QString ExtraDebugging = "Extra Debugging";
const QString DontFadeOnVoxelServerChanges = "Don't Fade In/Out on Voxel Server Changes"; const QString DontFadeOnVoxelServerChanges = "Don't Fade In/Out on Voxel Server Changes";
const QString HeadMouse = "Head Mouse"; const QString HeadMouse = "Head Mouse";
const QString FaceMode = "Cycle Face Mode"; const QString FaceMode = "Cycle Face Mode";

View file

@ -13,7 +13,7 @@
#include <PerfStat.h> #include <PerfStat.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include "Menu.h" #include "Application.h"
#include "VoxelHideShowThread.h" #include "VoxelHideShowThread.h"
VoxelHideShowThread::VoxelHideShowThread(VoxelSystem* theSystem) : VoxelHideShowThread::VoxelHideShowThread(VoxelSystem* theSystem) :
@ -30,8 +30,8 @@ bool VoxelHideShowThread::process() {
_theSystem->checkForCulling(); _theSystem->checkForCulling();
uint64_t end = usecTimestampNow(); uint64_t end = usecTimestampNow();
uint64_t elapsed = end - start; uint64_t elapsed = end - start;
bool showExtraDebugging = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); bool showExtraDebugging = Application::getInstance()->getLogger()->extraDebugging();
if (showExtraDebugging && elapsed > USECS_PER_FRAME) { if (showExtraDebugging && elapsed > USECS_PER_FRAME) {
printf("VoxelHideShowThread::process()... checkForCulling took %llu\n", elapsed); printf("VoxelHideShowThread::process()... checkForCulling took %llu\n", elapsed);
} }

View file

@ -19,7 +19,8 @@ void VoxelPacketProcessor::processPacket(const HifiSockAddr& senderSockAddr, uns
"VoxelPacketProcessor::processPacket()"); "VoxelPacketProcessor::processPacket()");
const int WAY_BEHIND = 300; const int WAY_BEHIND = 300;
if (packetsToProcessCount() > WAY_BEHIND && Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) {
if (packetsToProcessCount() > WAY_BEHIND && Application::getInstance()->getLogger()->extraDebugging()) {
qDebug("VoxelPacketProcessor::processPacket() packets to process=%d\n", packetsToProcessCount()); qDebug("VoxelPacketProcessor::processPacket() packets to process=%d\n", packetsToProcessCount());
} }
ssize_t messageLength = packetLength; ssize_t messageLength = packetLength;

View file

@ -612,7 +612,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
lockTree(); lockTree();
VoxelPacketData packetData(packetIsCompressed); VoxelPacketData packetData(packetIsCompressed);
packetData.loadFinalizedContent(dataAt, sectionLength); packetData.loadFinalizedContent(dataAt, sectionLength);
if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) { if (Application::getInstance()->getLogger()->extraDebugging()) {
qDebug("VoxelSystem::parseData() ... Got Packet Section" qDebug("VoxelSystem::parseData() ... Got Packet Section"
" color:%s compressed:%s sequence: %u flight:%d usec size:%d data:%d" " color:%s compressed:%s sequence: %u flight:%d usec size:%d data:%d"
" subsection:%d sectionLength:%d uncompressed:%d\n", " subsection:%d sectionLength:%d uncompressed:%d\n",
@ -973,7 +973,7 @@ int VoxelSystem::updateNodeInArrays(VoxelTreeElement* node, bool reuseIndex, boo
// not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality // not render these Voxels. We need to think about ways to keep the entire scene intact but maybe lower quality
// possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this // possibly shifting down to lower LOD or something. This debug message is to help identify, if/when/how this
// state actually occurs. // state actually occurs.
if (Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging)) { if (Application::getInstance()->getLogger()->extraDebugging()) {
qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n"); qDebug("OHHHH NOOOOOO!!!! updateNodeInArrays() BAILING (_voxelsInWriteArrays >= _maxVoxels)\n");
} }
return 0; return 0;
@ -1964,7 +1964,7 @@ void VoxelSystem::hideOutOfView(bool forceFullFrustum) {
setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY); setupNewVoxelsForDrawingSingleNode(DONT_BAIL_EARLY);
} }
bool extraDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); bool extraDebugDetails = Application::getInstance()->getLogger()->extraDebugging();
if (extraDebugDetails) { if (extraDebugDetails) {
qDebug("hideOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld\n", qDebug("hideOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld\n",
args.nodesScanned, args.nodesRemoved, args.nodesInside, args.nodesScanned, args.nodesRemoved, args.nodesInside,

View file

@ -12,7 +12,6 @@
#include "SharedUtil.h" #include "SharedUtil.h"
#include "ui/LogDialog.h" #include "ui/LogDialog.h"
#include "LogDisplay.h"
const int TOP_BAR_HEIGHT = 46; const int TOP_BAR_HEIGHT = 46;
const int INITIAL_WIDTH = 720; const int INITIAL_WIDTH = 720;
@ -27,11 +26,12 @@ const int CHECKBOX_WIDTH = 140;
const int REVEAL_BUTTON_WIDTH = 122; const int REVEAL_BUTTON_WIDTH = 122;
const float INITIAL_HEIGHT_RATIO = 0.6f; const float INITIAL_HEIGHT_RATIO = 0.6f;
int cursorMeta = qRegisterMetaType<QTextCursor>("QTextCursor"); int qTextCursorMeta = qRegisterMetaType<QTextCursor>("QTextCursor");
int blockMeta = qRegisterMetaType<QTextBlock>("QTextBlock"); int qTextBlockMeta = qRegisterMetaType<QTextBlock>("QTextBlock");
LogDialog::LogDialog(QWidget* parent) : QDialog(parent, Qt::Dialog) { LogDialog::LogDialog(QWidget* parent, AbstractLoggerInterface* logger) : QDialog(parent, Qt::Dialog) {
_logger = logger;
setWindowTitle("Log"); setWindowTitle("Log");
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -72,10 +72,13 @@ void LogDialog::initControls() {
_searchTextBox->setGeometry(left, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT); _searchTextBox->setGeometry(left, ELEMENT_MARGIN, SEARCH_TEXT_WIDTH, ELEMENT_HEIGHT);
left += SEARCH_TEXT_WIDTH + CHECKBOX_MARGIN; left += SEARCH_TEXT_WIDTH + CHECKBOX_MARGIN;
_searchTextBox->show(); _searchTextBox->show();
connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSeachTextChanged(QString))); connect(_searchTextBox, SIGNAL(textChanged(QString)), SLOT(handleSearchTextChanged(QString)));
_extraDebuggingBox = new QCheckBox("Extra debugging", this); _extraDebuggingBox = new QCheckBox("Extra debugging", this);
_extraDebuggingBox->setGeometry(left, ELEMENT_MARGIN, CHECKBOX_WIDTH, ELEMENT_HEIGHT); _extraDebuggingBox->setGeometry(left, ELEMENT_MARGIN, CHECKBOX_WIDTH, ELEMENT_HEIGHT);
if (_logger->extraDebugging()) {
_extraDebuggingBox->setCheckState(Qt::Checked);
}
_extraDebuggingBox->show(); _extraDebuggingBox->show();
connect(_extraDebuggingBox, SIGNAL(stateChanged(int)), SLOT(handleExtraDebuggingCheckbox(int))); connect(_extraDebuggingBox, SIGNAL(stateChanged(int)), SLOT(handleExtraDebuggingCheckbox(int)));
@ -91,22 +94,12 @@ void LogDialog::initControls() {
} }
void LogDialog::showEvent(QShowEvent *e) { void LogDialog::showEvent(QShowEvent*) {
_searchTextBox->clear(); connect(_logger, SIGNAL(logReceived(QString)), this, SLOT(appendLogLine(QString)));
_searchTextBox->setText(""); handleSearchTextChanged("");
/* pthread_mutex_lock(& _mutex);
QStringList _logData = LogDisplay::instance.getLogData("");
connect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine);
for(int i = 0; i < _logData.size(); ++i) {
appendLogLine(_logData[i]);
}
pthread_mutex_unlock(& _mutex);*/
} }
void LogDialog::resizeEvent(QResizeEvent *e) { void LogDialog::resizeEvent(QResizeEvent*) {
_logTextBox->setGeometry(0, TOP_BAR_HEIGHT, width(), height() - TOP_BAR_HEIGHT); _logTextBox->setGeometry(0, TOP_BAR_HEIGHT, width(), height() - TOP_BAR_HEIGHT);
_revealLogButton->setGeometry(width() - ELEMENT_MARGIN - REVEAL_BUTTON_WIDTH, _revealLogButton->setGeometry(width() - ELEMENT_MARGIN - REVEAL_BUTTON_WIDTH,
ELEMENT_MARGIN, ELEMENT_MARGIN,
@ -117,7 +110,9 @@ void LogDialog::resizeEvent(QResizeEvent *e) {
void LogDialog::appendLogLine(QString logLine) { void LogDialog::appendLogLine(QString logLine) {
if (isVisible()) { if (isVisible()) {
pthread_mutex_lock(& _mutex); pthread_mutex_lock(& _mutex);
_logTextBox->appendPlainText(logLine.simplified());
QString line = logLine.replace(QRegExp("node"), "<b>node</b>");
_logTextBox->appendHtml(line);
pthread_mutex_unlock(& _mutex); pthread_mutex_unlock(& _mutex);
_logTextBox->ensureCursorVisible(); _logTextBox->ensureCursorVisible();
} }
@ -131,22 +126,16 @@ void LogDialog::handleRevealButton() {
} }
void LogDialog::handleExtraDebuggingCheckbox(int state) { void LogDialog::handleExtraDebuggingCheckbox(const int state) {
_logger->setExtraDebugging(state != 0);
} }
void LogDialog::handleSeachTextChanged(QString searchText) { void LogDialog::handleSearchTextChanged(const QString searchText) {
if (searchText.isEmpty()) {
connect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine);
} else {
disconnect(&LogDisplay::instance, &LogDisplay::logReceived, this, &LogDialog::appendLogLine);
}
_logTextBox->clear(); _logTextBox->clear();
pthread_mutex_lock(& _mutex); pthread_mutex_lock(& _mutex);
QStringList _logData = LogDisplay::instance.getLogData(searchText); QStringList _logData = _logger->getLogData(searchText);
for(int i = 0; i < _logData.size(); ++i) { for (int i = 0; i < _logData.size(); ++i) {
appendLogLine(_logData[i]); appendLogLine(_logData[i]);
} }

View file

@ -15,11 +15,13 @@
#include <QPushButton> #include <QPushButton>
#include <QCheckBox> #include <QCheckBox>
#include "AbstractLoggerInterface.h"
class LogDialog : public QDialog { class LogDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
LogDialog(QWidget* parent); LogDialog(QWidget*, AbstractLoggerInterface*);
~LogDialog(); ~LogDialog();
public slots: public slots:
@ -29,7 +31,7 @@ private slots:
void handleSearchButton(); void handleSearchButton();
void handleRevealButton(); void handleRevealButton();
void handleExtraDebuggingCheckbox(const int); void handleExtraDebuggingCheckbox(const int);
void handleSeachTextChanged(QString); void handleSearchTextChanged(const QString);
protected: protected:
void resizeEvent(QResizeEvent*); void resizeEvent(QResizeEvent*);
@ -43,6 +45,8 @@ private:
QPlainTextEdit* _logTextBox; QPlainTextEdit* _logTextBox;
pthread_mutex_t _mutex; pthread_mutex_t _mutex;
AbstractLoggerInterface* _logger;
void initControls(); void initControls();
}; };