diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 3b4300b6fd..8fe618b70d 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -175,9 +175,6 @@ AssignmentClient::~AssignmentClient() { void AssignmentClient::aboutToQuit() { stopAssignmentClient(); - - // clear the log handler so that Qt doesn't call the destructor on LogHandler - qInstallMessageHandler(0); } void AssignmentClient::setUpStatusToMonitor() { diff --git a/assignment-client/src/AssignmentClientApp.cpp b/assignment-client/src/AssignmentClientApp.cpp index c425a239dd..68e7b9b997 100644 --- a/assignment-client/src/AssignmentClientApp.cpp +++ b/assignment-client/src/AssignmentClientApp.cpp @@ -45,9 +45,6 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : setApplicationName("assignment-client"); setApplicationVersion(BuildInfo::VERSION); - // use the verbose message handler in Logging - qInstallMessageHandler(LogHandler::verboseMessageHandler); - // parse command-line QCommandLineParser parser; parser.setApplicationDescription("High Fidelity Assignment Client"); diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index 8ba253d549..1ee876ceea 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -126,9 +126,6 @@ void AssignmentClientMonitor::stopChildProcesses() { void AssignmentClientMonitor::aboutToQuit() { stopChildProcesses(); - - // clear the log handler so that Qt doesn't call the destructor on LogHandler - qInstallMessageHandler(0); } void AssignmentClientMonitor::spawnChildClient() { diff --git a/assignment-client/src/main.cpp b/assignment-client/src/main.cpp index 052c4755f8..cf8d9ebe31 100644 --- a/assignment-client/src/main.cpp +++ b/assignment-client/src/main.cpp @@ -9,8 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - +#include #include #include "AssignmentClientApp.h" @@ -18,10 +17,14 @@ int main(int argc, char* argv[]) { disableQtBearerPoll(); // Fixes wifi ping spikes + qInstallMessageHandler(LogHandler::verboseMessageHandler); + qInfo() << "Starting."; + AssignmentClientApp app(argc, argv); int acReturn = app.exec(); qDebug() << "assignment-client process" << app.applicationPid() << "exiting with status code" << acReturn; - + + qInfo() << "Quitting."; return acReturn; } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8b73b851b2..d13f9b883f 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -72,13 +72,10 @@ DomainServer::DomainServer(int argc, char* argv[]) : _iceServerPort(ICE_SERVER_DEFAULT_PORT) { parseCommandLine(); - qInstallMessageHandler(LogHandler::verboseMessageHandler); LogUtils::init(); Setting::init(); - connect(this, &QCoreApplication::aboutToQuit, this, &DomainServer::aboutToQuit); - setOrganizationName(BuildInfo::MODIFIED_ORGANIZATION); setOrganizationDomain("highfidelity.io"); setApplicationName("domain-server"); @@ -211,6 +208,7 @@ void DomainServer::parseCommandLine() { } DomainServer::~DomainServer() { + qInfo() << "Domain Server is shutting down."; // destroy the LimitedNodeList before the DomainServer QCoreApplication is down DependencyManager::destroy(); } @@ -223,12 +221,6 @@ void DomainServer::queuedQuit(QString quitMessage, int 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() { qDebug() << "domain-server is restarting."; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 6330cf51a5..c14ec5eee0 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -72,8 +72,6 @@ public slots: void processICEServerHeartbeatACK(QSharedPointer message); private slots: - void aboutToQuit(); - void setupPendingAssignmentCredits(); void sendPendingTransactionsToServer(); @@ -150,13 +148,9 @@ private: bool isAuthenticatedRequest(HTTPConnection* connection, const QUrl& url); - void handleTokenRequestFinished(); QNetworkReply* profileRequestGivenTokenReply(QNetworkReply* tokenReply); - void handleProfileRequestFinished(); Headers setupCookieHeadersFromProfileReply(QNetworkReply* profileReply); - void loadExistingSessionsFromSettings(); - QJsonObject jsonForSocket(const HifiSockAddr& socket); QJsonObject jsonObjectForNode(const SharedNodePointer& node); diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index b3b5c8b9be..fdf7a598aa 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -15,8 +15,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include #include @@ -29,6 +27,9 @@ int main(int argc, char* argv[]) { setvbuf(stdout, NULL, _IOLBF, 0); #endif + qInstallMessageHandler(LogHandler::verboseMessageHandler); + qInfo() << "Starting."; + int currentExitCode = 0; // use a do-while to handle domain-server restart @@ -37,7 +38,7 @@ int main(int argc, char* argv[]) { currentExitCode = domainServer.exec(); } while (currentExitCode == DomainServer::EXIT_CODE_REBOOT); - + qInfo() << "Quitting."; return currentExitCode; } diff --git a/ice-server/src/main.cpp b/ice-server/src/main.cpp index 2326984668..ec8b9957cf 100644 --- a/ice-server/src/main.cpp +++ b/ice-server/src/main.cpp @@ -19,8 +19,9 @@ int main(int argc, char* argv[]) { #ifndef WIN32 setvbuf(stdout, NULL, _IOLBF, 0); #endif - + qInstallMessageHandler(LogHandler::verboseMessageHandler); + qInfo() << "Starting."; IceServer iceServer(argc, argv); return iceServer.exec(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 867761e012..ffe62f71de 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1654,7 +1654,8 @@ Application::~Application() { _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() { diff --git a/libraries/shared/src/LogHandler.cpp b/libraries/shared/src/LogHandler.cpp index d142e3f839..35a3361c38 100644 --- a/libraries/shared/src/LogHandler.cpp +++ b/libraries/shared/src/LogHandler.cpp @@ -10,17 +10,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - -#include -#include -#include -#include -#include -#include - #include "LogHandler.h" +#include + +#include +#include +#include +#include +#include +#include +#include + QMutex LogHandler::_mutex; LogHandler& LogHandler::getInstance() { @@ -28,16 +29,15 @@ LogHandler& LogHandler::getInstance() { return staticInstance; } -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); - +LogHandler::LogHandler() { // when the log handler is first setup we should print our timezone 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) { @@ -165,7 +165,7 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont stringForLogType(type), context.category); if (_shouldOutputProcessID) { - prefixString.append(QString(" [%1]").arg(QCoreApplication::instance()->applicationPid())); + prefixString.append(QString(" [%1]").arg(QCoreApplication::applicationPid())); } if (_shouldOutputThreadID) { @@ -187,6 +187,14 @@ void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext& } 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); return *_repeatedMessageRegexes.insert(regexString); } diff --git a/libraries/shared/src/LogHandler.h b/libraries/shared/src/LogHandler.h index 890497b891..f80fad4c6a 100644 --- a/libraries/shared/src/LogHandler.h +++ b/libraries/shared/src/LogHandler.h @@ -52,8 +52,10 @@ public: const QString& addRepeatedMessageRegex(const QString& regexString); const QString& addOnlyOnceMessageRegex(const QString& regexString); + private: LogHandler(); + ~LogHandler(); void flushRepeatedMessages(); diff --git a/libraries/shared/src/ShutdownEventListener.cpp b/libraries/shared/src/ShutdownEventListener.cpp index e640126b7b..6f043cd43e 100644 --- a/libraries/shared/src/ShutdownEventListener.cpp +++ b/libraries/shared/src/ShutdownEventListener.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "ShutdownEventListener.h" #ifdef Q_OS_WIN @@ -19,6 +17,9 @@ #include #endif +#include +#include + ShutdownEventListener& ShutdownEventListener::getInstance() { static ShutdownEventListener staticInstance; return staticInstance; @@ -29,9 +30,7 @@ void signalHandler(int param) { QMetaObject::invokeMethod(qApp, "quit"); } -ShutdownEventListener::ShutdownEventListener(QObject* parent) : - QObject(parent) -{ +ShutdownEventListener::ShutdownEventListener(QObject* parent) : QObject(parent) { #ifndef Q_OS_WIN // be a signal handler for SIGTERM so we can stop our children when we get it signal(SIGTERM, signalHandler); diff --git a/libraries/shared/src/shared/FileLogger.cpp b/libraries/shared/src/shared/FileLogger.cpp index ef3436a8d7..143438ba68 100644 --- a/libraries/shared/src/shared/FileLogger.cpp +++ b/libraries/shared/src/shared/FileLogger.cpp @@ -109,7 +109,8 @@ bool FilePersistThread::processQueueItems(const Queue& messages) { } FileLogger::FileLogger(QObject* parent) : - AbstractLoggerInterface(parent), _fileName(getLogFilename()) + AbstractLoggerInterface(parent), + _fileName(getLogFilename()) { _persistThreadInstance = new FilePersistThread(*this); _persistThreadInstance->initialize(true, QThread::LowestPriority); diff --git a/libraries/shared/src/shared/FileLogger.h b/libraries/shared/src/shared/FileLogger.h index 697b96c6d8..f0f6dd5c09 100644 --- a/libraries/shared/src/shared/FileLogger.h +++ b/libraries/shared/src/shared/FileLogger.h @@ -24,7 +24,7 @@ public: FileLogger(QObject* parent = NULL); virtual ~FileLogger(); - QString getFilename() { return _fileName; } + QString getFilename() const { return _fileName; } virtual void addMessage(const QString&) override; virtual QString getLogData() override; virtual void locateLog() override;