mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 04:24:47 +02:00
Logging improvements
This commit is contained in:
parent
9a774553ae
commit
ae29fe8ab2
14 changed files with 50 additions and 57 deletions
|
@ -175,9 +175,6 @@ AssignmentClient::~AssignmentClient() {
|
||||||
|
|
||||||
void AssignmentClient::aboutToQuit() {
|
void AssignmentClient::aboutToQuit() {
|
||||||
stopAssignmentClient();
|
stopAssignmentClient();
|
||||||
|
|
||||||
// clear the log handler so that Qt doesn't call the destructor on LogHandler
|
|
||||||
qInstallMessageHandler(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentClient::setUpStatusToMonitor() {
|
void AssignmentClient::setUpStatusToMonitor() {
|
||||||
|
|
|
@ -45,9 +45,6 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
setApplicationName("assignment-client");
|
setApplicationName("assignment-client");
|
||||||
setApplicationVersion(BuildInfo::VERSION);
|
setApplicationVersion(BuildInfo::VERSION);
|
||||||
|
|
||||||
// use the verbose message handler in Logging
|
|
||||||
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
|
||||||
|
|
||||||
// parse command-line
|
// parse command-line
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("High Fidelity Assignment Client");
|
parser.setApplicationDescription("High Fidelity Assignment Client");
|
||||||
|
|
|
@ -126,9 +126,6 @@ void AssignmentClientMonitor::stopChildProcesses() {
|
||||||
|
|
||||||
void AssignmentClientMonitor::aboutToQuit() {
|
void AssignmentClientMonitor::aboutToQuit() {
|
||||||
stopChildProcesses();
|
stopChildProcesses();
|
||||||
|
|
||||||
// clear the log handler so that Qt doesn't call the destructor on LogHandler
|
|
||||||
qInstallMessageHandler(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentClientMonitor::spawnChildClient() {
|
void AssignmentClientMonitor::spawnChildClient() {
|
||||||
|
|
|
@ -9,8 +9,7 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "AssignmentClientApp.h"
|
#include "AssignmentClientApp.h"
|
||||||
|
@ -18,10 +17,14 @@
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
disableQtBearerPoll(); // Fixes wifi ping spikes
|
disableQtBearerPoll(); // Fixes wifi ping spikes
|
||||||
|
|
||||||
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
qInfo() << "Starting.";
|
||||||
|
|
||||||
AssignmentClientApp app(argc, argv);
|
AssignmentClientApp app(argc, argv);
|
||||||
|
|
||||||
int acReturn = app.exec();
|
int acReturn = app.exec();
|
||||||
qDebug() << "assignment-client process" << app.applicationPid() << "exiting with status code" << acReturn;
|
qDebug() << "assignment-client process" << app.applicationPid() << "exiting with status code" << acReturn;
|
||||||
|
|
||||||
|
qInfo() << "Quitting.";
|
||||||
return acReturn;
|
return acReturn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,13 +72,10 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
||||||
_iceServerPort(ICE_SERVER_DEFAULT_PORT)
|
_iceServerPort(ICE_SERVER_DEFAULT_PORT)
|
||||||
{
|
{
|
||||||
parseCommandLine();
|
parseCommandLine();
|
||||||
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
|
||||||
|
|
||||||
LogUtils::init();
|
LogUtils::init();
|
||||||
Setting::init();
|
Setting::init();
|
||||||
|
|
||||||
connect(this, &QCoreApplication::aboutToQuit, this, &DomainServer::aboutToQuit);
|
|
||||||
|
|
||||||
setOrganizationName(BuildInfo::MODIFIED_ORGANIZATION);
|
setOrganizationName(BuildInfo::MODIFIED_ORGANIZATION);
|
||||||
setOrganizationDomain("highfidelity.io");
|
setOrganizationDomain("highfidelity.io");
|
||||||
setApplicationName("domain-server");
|
setApplicationName("domain-server");
|
||||||
|
@ -211,6 +208,7 @@ void DomainServer::parseCommandLine() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DomainServer::~DomainServer() {
|
DomainServer::~DomainServer() {
|
||||||
|
qInfo() << "Domain Server is shutting down.";
|
||||||
// destroy the LimitedNodeList before the DomainServer QCoreApplication is down
|
// destroy the LimitedNodeList before the DomainServer QCoreApplication is down
|
||||||
DependencyManager::destroy<LimitedNodeList>();
|
DependencyManager::destroy<LimitedNodeList>();
|
||||||
}
|
}
|
||||||
|
@ -223,12 +221,6 @@ void DomainServer::queuedQuit(QString quitMessage, int exitCode) {
|
||||||
QCoreApplication::exit(exitCode);
|
QCoreApplication::exit(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainServer::aboutToQuit() {
|
|
||||||
|
|
||||||
// clear the log handler so that Qt doesn't call the destructor on LogHandler
|
|
||||||
qInstallMessageHandler(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DomainServer::restart() {
|
void DomainServer::restart() {
|
||||||
qDebug() << "domain-server is restarting.";
|
qDebug() << "domain-server is restarting.";
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,6 @@ public slots:
|
||||||
void processICEServerHeartbeatACK(QSharedPointer<ReceivedMessage> message);
|
void processICEServerHeartbeatACK(QSharedPointer<ReceivedMessage> message);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void aboutToQuit();
|
|
||||||
|
|
||||||
void setupPendingAssignmentCredits();
|
void setupPendingAssignmentCredits();
|
||||||
void sendPendingTransactionsToServer();
|
void sendPendingTransactionsToServer();
|
||||||
|
|
||||||
|
@ -150,13 +148,9 @@ private:
|
||||||
|
|
||||||
bool isAuthenticatedRequest(HTTPConnection* connection, const QUrl& url);
|
bool isAuthenticatedRequest(HTTPConnection* connection, const QUrl& url);
|
||||||
|
|
||||||
void handleTokenRequestFinished();
|
|
||||||
QNetworkReply* profileRequestGivenTokenReply(QNetworkReply* tokenReply);
|
QNetworkReply* profileRequestGivenTokenReply(QNetworkReply* tokenReply);
|
||||||
void handleProfileRequestFinished();
|
|
||||||
Headers setupCookieHeadersFromProfileReply(QNetworkReply* profileReply);
|
Headers setupCookieHeadersFromProfileReply(QNetworkReply* profileReply);
|
||||||
|
|
||||||
void loadExistingSessionsFromSettings();
|
|
||||||
|
|
||||||
QJsonObject jsonForSocket(const HifiSockAddr& socket);
|
QJsonObject jsonForSocket(const HifiSockAddr& socket);
|
||||||
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
|
QJsonObject jsonObjectForNode(const SharedNodePointer& node);
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
|
|
||||||
#include <LogHandler.h>
|
#include <LogHandler.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
|
@ -29,6 +27,9 @@ int main(int argc, char* argv[]) {
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
qInfo() << "Starting.";
|
||||||
|
|
||||||
int currentExitCode = 0;
|
int currentExitCode = 0;
|
||||||
|
|
||||||
// use a do-while to handle domain-server restart
|
// use a do-while to handle domain-server restart
|
||||||
|
@ -37,7 +38,7 @@ int main(int argc, char* argv[]) {
|
||||||
currentExitCode = domainServer.exec();
|
currentExitCode = domainServer.exec();
|
||||||
} while (currentExitCode == DomainServer::EXIT_CODE_REBOOT);
|
} while (currentExitCode == DomainServer::EXIT_CODE_REBOOT);
|
||||||
|
|
||||||
|
qInfo() << "Quitting.";
|
||||||
return currentExitCode;
|
return currentExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,9 @@ int main(int argc, char* argv[]) {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
qInfo() << "Starting.";
|
||||||
|
|
||||||
IceServer iceServer(argc, argv);
|
IceServer iceServer(argc, argv);
|
||||||
return iceServer.exec();
|
return iceServer.exec();
|
||||||
|
|
|
@ -1654,7 +1654,8 @@ Application::~Application() {
|
||||||
|
|
||||||
_window->deleteLater();
|
_window->deleteLater();
|
||||||
|
|
||||||
qInstallMessageHandler(nullptr); // NOTE: Do this as late as possible so we continue to get our log messages
|
// Can't log to file passed this point, FileLogger about to be deleted
|
||||||
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initializeGL() {
|
void Application::initializeGL() {
|
||||||
|
|
|
@ -10,17 +10,18 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <qcoreapplication.h>
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QThread>
|
|
||||||
#include <QMutexLocker>
|
|
||||||
#include <QRegExp>
|
|
||||||
|
|
||||||
#include "LogHandler.h"
|
#include "LogHandler.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtCore/QDateTime>
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QMutexLocker>
|
||||||
|
#include <QtCore/QRegExp>
|
||||||
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
QMutex LogHandler::_mutex;
|
QMutex LogHandler::_mutex;
|
||||||
|
|
||||||
LogHandler& LogHandler::getInstance() {
|
LogHandler& LogHandler::getInstance() {
|
||||||
|
@ -28,16 +29,15 @@ LogHandler& LogHandler::getInstance() {
|
||||||
return staticInstance;
|
return staticInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogHandler::LogHandler()
|
LogHandler::LogHandler() {
|
||||||
{
|
|
||||||
// setup our timer to flush the verbose logs every 5 seconds
|
|
||||||
QTimer* logFlushTimer = new QTimer(this);
|
|
||||||
connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages);
|
|
||||||
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
|
||||||
|
|
||||||
// when the log handler is first setup we should print our timezone
|
// when the log handler is first setup we should print our timezone
|
||||||
QString timezoneString = "Time zone: " + QDateTime::currentDateTime().toString("t");
|
QString timezoneString = "Time zone: " + QDateTime::currentDateTime().toString("t");
|
||||||
printf("%s\n", qPrintable(timezoneString));
|
printMessage(LogMsgType::LogInfo, QMessageLogContext(), timezoneString);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogHandler::~LogHandler() {
|
||||||
|
flushRepeatedMessages();
|
||||||
|
printMessage(LogMsgType::LogDebug, QMessageLogContext(), "LogHandler shutdown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* stringForLogType(LogMsgType msgType) {
|
const char* stringForLogType(LogMsgType msgType) {
|
||||||
|
@ -165,7 +165,7 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont
|
||||||
stringForLogType(type), context.category);
|
stringForLogType(type), context.category);
|
||||||
|
|
||||||
if (_shouldOutputProcessID) {
|
if (_shouldOutputProcessID) {
|
||||||
prefixString.append(QString(" [%1]").arg(QCoreApplication::instance()->applicationPid()));
|
prefixString.append(QString(" [%1]").arg(QCoreApplication::applicationPid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_shouldOutputThreadID) {
|
if (_shouldOutputThreadID) {
|
||||||
|
@ -187,6 +187,14 @@ void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext&
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) {
|
const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) {
|
||||||
|
static std::once_flag once;
|
||||||
|
std::call_once(once, [&] {
|
||||||
|
// setup our timer to flush the verbose logs every 5 seconds
|
||||||
|
QTimer* logFlushTimer = new QTimer(this);
|
||||||
|
connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages);
|
||||||
|
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
||||||
|
});
|
||||||
|
|
||||||
QMutexLocker lock(&_mutex);
|
QMutexLocker lock(&_mutex);
|
||||||
return *_repeatedMessageRegexes.insert(regexString);
|
return *_repeatedMessageRegexes.insert(regexString);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,10 @@ public:
|
||||||
|
|
||||||
const QString& addRepeatedMessageRegex(const QString& regexString);
|
const QString& addRepeatedMessageRegex(const QString& regexString);
|
||||||
const QString& addOnlyOnceMessageRegex(const QString& regexString);
|
const QString& addOnlyOnceMessageRegex(const QString& regexString);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogHandler();
|
LogHandler();
|
||||||
|
~LogHandler();
|
||||||
|
|
||||||
void flushRepeatedMessages();
|
void flushRepeatedMessages();
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
|
|
||||||
#include "ShutdownEventListener.h"
|
#include "ShutdownEventListener.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -19,6 +17,9 @@
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
ShutdownEventListener& ShutdownEventListener::getInstance() {
|
ShutdownEventListener& ShutdownEventListener::getInstance() {
|
||||||
static ShutdownEventListener staticInstance;
|
static ShutdownEventListener staticInstance;
|
||||||
return staticInstance;
|
return staticInstance;
|
||||||
|
@ -29,9 +30,7 @@ void signalHandler(int param) {
|
||||||
QMetaObject::invokeMethod(qApp, "quit");
|
QMetaObject::invokeMethod(qApp, "quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
ShutdownEventListener::ShutdownEventListener(QObject* parent) :
|
ShutdownEventListener::ShutdownEventListener(QObject* parent) : QObject(parent) {
|
||||||
QObject(parent)
|
|
||||||
{
|
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
// be a signal handler for SIGTERM so we can stop our children when we get it
|
// be a signal handler for SIGTERM so we can stop our children when we get it
|
||||||
signal(SIGTERM, signalHandler);
|
signal(SIGTERM, signalHandler);
|
||||||
|
|
|
@ -109,7 +109,8 @@ bool FilePersistThread::processQueueItems(const Queue& messages) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLogger::FileLogger(QObject* parent) :
|
FileLogger::FileLogger(QObject* parent) :
|
||||||
AbstractLoggerInterface(parent), _fileName(getLogFilename())
|
AbstractLoggerInterface(parent),
|
||||||
|
_fileName(getLogFilename())
|
||||||
{
|
{
|
||||||
_persistThreadInstance = new FilePersistThread(*this);
|
_persistThreadInstance = new FilePersistThread(*this);
|
||||||
_persistThreadInstance->initialize(true, QThread::LowestPriority);
|
_persistThreadInstance->initialize(true, QThread::LowestPriority);
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
FileLogger(QObject* parent = NULL);
|
FileLogger(QObject* parent = NULL);
|
||||||
virtual ~FileLogger();
|
virtual ~FileLogger();
|
||||||
|
|
||||||
QString getFilename() { return _fileName; }
|
QString getFilename() const { return _fileName; }
|
||||||
virtual void addMessage(const QString&) override;
|
virtual void addMessage(const QString&) override;
|
||||||
virtual QString getLogData() override;
|
virtual QString getLogData() override;
|
||||||
virtual void locateLog() override;
|
virtual void locateLog() override;
|
||||||
|
|
Loading…
Reference in a new issue