Reveal log file

- change log location lo application data folder
- reveal file in Finder (Explorer) implementation
This commit is contained in:
Stojce Slavkovski 2013-12-23 21:23:47 +01:00
parent 505ed5bc64
commit 840d1a33ef
7 changed files with 101 additions and 9 deletions

View file

@ -22,6 +22,7 @@ public:
virtual void addMessage(QString) = 0;
virtual QStringList getLogData(QString) = 0;
virtual void locateLog() = 0;
signals:
void logReceived(QString message);
@ -30,4 +31,4 @@ private:
bool _extraDebugging = false;
};
#endif /* defined(__hifi__AbstractAudioInterface__) */
#endif /* defined(__interface__AbstractLoggerInterface__) */

View file

@ -141,7 +141,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_recentMaxPackets(0),
_resetRecentMaxPacketsSoon(true),
_swatch(NULL),
_pasteMode(false)
_pasteMode(false),
_logger(new FileLogger())
{
_applicationStartupTime = startup_time;
@ -149,8 +150,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
QFontDatabase::addApplicationFont("resources/styles/Inconsolata.otf");
_window->setWindowTitle("Interface");
_logger = new FileLogger();
qInstallMessageHandler(messageHandler);
// call Menu getInstance static method to set up the menu
@ -269,7 +268,8 @@ Application::~Application() {
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
Menu::getInstance()->deleteLater();
delete _logger;
delete _settings;
delete _followMode;
delete _glWidget;

View file

@ -8,13 +8,23 @@
#include "FileLogger.h"
#include "HifiSockAddr.h"
#include <FileUtils.h>
#include <QDateTime>
#include <QFile>
#include <QDir>
#include <QDesktopServices>
FileLogger::FileLogger() : _lines(NULL) {
QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress());
QDateTime now = QDateTime::currentDateTime();
_fileName = QString("hifi-log_%1_%2.txt").arg(clientAddress.toString(), now.toString("yyyy-MM-dd_hh.mm.ss"));
_fileName = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QDir logDir(_fileName);
if (!logDir.exists(_fileName)) {
logDir.mkdir(_fileName);
}
_fileName.append(QString("/hifi-log_%1_%2.txt").arg(clientAddress.toString(), now.toString("yyyy-MM-dd_hh.mm.ss")));
setExtraDebugging(false);
}
@ -41,10 +51,13 @@ void FileLogger::addMessage(QString message) {
_lines.append(message);
QFile file(_fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
QTextStream out(&file);
out << message;
}
_mutex.unlock();
}
}
void FileLogger::locateLog() {
FileUtils::LocateFile(_fileName);
}

View file

@ -19,6 +19,7 @@ public:
virtual void addMessage(QString);
virtual QStringList getLogData(QString);
virtual void locateLog();
private:
QStringList _lines;

View file

@ -121,7 +121,7 @@ void LogDialog::handleSearchButton() {
}
void LogDialog::handleRevealButton() {
_logger->locateLog();
}
void LogDialog::handleExtraDebuggingCheckbox(const int state) {

View file

@ -0,0 +1,56 @@
//
// FileUtils.cpp
// hifi
//
// Created by Stojce Slavkovski on 12/23/13.
//
//
#include "FileUtils.h"
#include <QtCore>
#include <QDesktopServices>
void FileUtils::LocateFile(QString filePath) {
// adopted from
// http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
// and
// http://lynxline.com/show-in-finder-show-in-explorer/
QFileInfo fileInfo(filePath);
if (!fileInfo.exists()) {
return;
}
bool success = false;
#ifdef Q_OS_MAC
QStringList args;
args << "-e";
args << "tell application \"Finder\"";
args << "-e";
args << "activate";
args << "-e";
args << "select POSIX file \"" + fileInfo.absoluteFilePath().toUtf8() + "\"";
args << "-e";
args << "end tell";
success = QProcess::startDetached("osascript", args);
#endif
#ifdef Q_OS_WIN
QStringList args;
// don't send `select` command switch if `filePath` is folder
if (!fileInfo.isDir()) {
args << "/select,";
}
args += QDir::toNativeSeparators(fileInfo.absoluteFilePath().toUtf8());
success = QProcess::startDetached("explorer", args);
#endif
// fallback, open enclosing folder
if (!success) {
const QString folder = fileInfo.path();
QDesktopServices::openUrl(QUrl::fromLocalFile(folder));
}
}

View file

@ -0,0 +1,21 @@
//
// FileUtils.h
// hifi
//
// Created by Stojce Slavkovski on 12/23/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#ifndef hifi_FileUtils_h
#define hifi_FileUtils_h
#include <QString>
class FileUtils {
public:
static void LocateFile(QString);
};
#endif