mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 03:19:24 +02:00
Reveal log file
- change log location lo application data folder - reveal file in Finder (Explorer) implementation
This commit is contained in:
parent
505ed5bc64
commit
840d1a33ef
7 changed files with 101 additions and 9 deletions
|
@ -22,6 +22,7 @@ public:
|
||||||
|
|
||||||
virtual void addMessage(QString) = 0;
|
virtual void addMessage(QString) = 0;
|
||||||
virtual QStringList getLogData(QString) = 0;
|
virtual QStringList getLogData(QString) = 0;
|
||||||
|
virtual void locateLog() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void logReceived(QString message);
|
void logReceived(QString message);
|
||||||
|
@ -30,4 +31,4 @@ private:
|
||||||
bool _extraDebugging = false;
|
bool _extraDebugging = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AbstractAudioInterface__) */
|
#endif /* defined(__interface__AbstractLoggerInterface__) */
|
||||||
|
|
|
@ -141,7 +141,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_recentMaxPackets(0),
|
_recentMaxPackets(0),
|
||||||
_resetRecentMaxPacketsSoon(true),
|
_resetRecentMaxPacketsSoon(true),
|
||||||
_swatch(NULL),
|
_swatch(NULL),
|
||||||
_pasteMode(false)
|
_pasteMode(false),
|
||||||
|
_logger(new FileLogger())
|
||||||
{
|
{
|
||||||
_applicationStartupTime = startup_time;
|
_applicationStartupTime = startup_time;
|
||||||
|
|
||||||
|
@ -149,8 +150,6 @@ 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
|
||||||
|
@ -269,7 +268,8 @@ Application::~Application() {
|
||||||
|
|
||||||
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
|
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
|
||||||
Menu::getInstance()->deleteLater();
|
Menu::getInstance()->deleteLater();
|
||||||
|
|
||||||
|
delete _logger;
|
||||||
delete _settings;
|
delete _settings;
|
||||||
delete _followMode;
|
delete _followMode;
|
||||||
delete _glWidget;
|
delete _glWidget;
|
||||||
|
|
|
@ -8,13 +8,23 @@
|
||||||
|
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
|
#include <FileUtils.h>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
FileLogger::FileLogger() : _lines(NULL) {
|
FileLogger::FileLogger() : _lines(NULL) {
|
||||||
QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress());
|
QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress());
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
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);
|
setExtraDebugging(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +51,13 @@ void FileLogger::addMessage(QString message) {
|
||||||
_lines.append(message);
|
_lines.append(message);
|
||||||
|
|
||||||
QFile file(_fileName);
|
QFile file(_fileName);
|
||||||
|
|
||||||
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||||
QTextStream out(&file);
|
QTextStream out(&file);
|
||||||
out << message;
|
out << message;
|
||||||
}
|
}
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileLogger::locateLog() {
|
||||||
|
FileUtils::LocateFile(_fileName);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
|
|
||||||
virtual void addMessage(QString);
|
virtual void addMessage(QString);
|
||||||
virtual QStringList getLogData(QString);
|
virtual QStringList getLogData(QString);
|
||||||
|
virtual void locateLog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList _lines;
|
QStringList _lines;
|
||||||
|
|
|
@ -121,7 +121,7 @@ void LogDialog::handleSearchButton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogDialog::handleRevealButton() {
|
void LogDialog::handleRevealButton() {
|
||||||
|
_logger->locateLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogDialog::handleExtraDebuggingCheckbox(const int state) {
|
void LogDialog::handleExtraDebuggingCheckbox(const int state) {
|
||||||
|
|
56
libraries/shared/src/FileUtils.cpp
Normal file
56
libraries/shared/src/FileUtils.cpp
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
21
libraries/shared/src/FileUtils.h
Normal file
21
libraries/shared/src/FileUtils.h
Normal 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
|
Loading…
Reference in a new issue