mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:03:11 +02:00
move Logging to LogHandler
This commit is contained in:
parent
2711ff2b5f
commit
d3bbd251db
14 changed files with 60 additions and 54 deletions
|
@ -16,7 +16,7 @@
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
#include <Assignment.h>
|
#include <Assignment.h>
|
||||||
#include <HifiConfigVariantMap.h>
|
#include <HifiConfigVariantMap.h>
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <LogUtils.h>
|
#include <LogUtils.h>
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
|
@ -51,7 +51,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
||||||
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
|
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
|
||||||
|
|
||||||
// set the logging target to the the CHILD_TARGET_NAME
|
// set the logging target to the the CHILD_TARGET_NAME
|
||||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||||
|
|
||||||
const QVariantMap argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments());
|
const QVariantMap argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments());
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ void AssignmentClient::handleAuthenticationRequest() {
|
||||||
|
|
||||||
void AssignmentClient::assignmentCompleted() {
|
void AssignmentClient::assignmentCompleted() {
|
||||||
// reset the logging target to the the CHILD_TARGET_NAME
|
// reset the logging target to the the CHILD_TARGET_NAME
|
||||||
Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
|
||||||
|
|
||||||
qDebug("Assignment finished or never started - waiting for new assignment.");
|
qDebug("Assignment finished or never started - waiting for new assignment.");
|
||||||
|
|
||||||
|
|
|
@ -9,7 +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 <Logging.h>
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "AssignmentClientMonitor.h"
|
#include "AssignmentClientMonitor.h"
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, int num
|
||||||
QCoreApplication(argc, argv)
|
QCoreApplication(argc, argv)
|
||||||
{
|
{
|
||||||
// start the Logging class with the parent's target name
|
// start the Logging class with the parent's target name
|
||||||
Logging::setTargetName(ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME);
|
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME);
|
||||||
|
|
||||||
_childArguments = arguments();
|
_childArguments = arguments();
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include <QtNetwork/QNetworkRequest>
|
#include <QtNetwork/QNetworkRequest>
|
||||||
#include <QtNetwork/QNetworkReply>
|
#include <QtNetwork/QNetworkReply>
|
||||||
|
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <NetworkAccessManager.h>
|
#include <NetworkAccessManager.h>
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
|
@ -9,7 +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 <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "Assignment.h"
|
#include "Assignment.h"
|
||||||
|
@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// use the verbose message handler in Logging
|
// use the verbose message handler in Logging
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
|
||||||
const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER);
|
const char* numForksString = getCmdOption(argc, (const char**)argv, NUM_FORKS_PARAMETER);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
#include <HTTPConnection.h>
|
#include <HTTPConnection.h>
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <UUID.h>
|
#include <UUID.h>
|
||||||
|
|
||||||
#include "../AssignmentClient.h"
|
#include "../AssignmentClient.h"
|
||||||
|
@ -923,7 +923,7 @@ void OctreeServer::run() {
|
||||||
|
|
||||||
beforeRun(); // after payload has been processed
|
beforeRun(); // after payload has been processed
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
|
||||||
const char* STATUS_PORT = "--statusPort";
|
const char* STATUS_PORT = "--statusPort";
|
||||||
const char* statusPort = getCmdOption(_argc, _argv, STATUS_PORT);
|
const char* statusPort = getCmdOption(_argc, _argv, STATUS_PORT);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "DomainServer.h"
|
#include "DomainServer.h"
|
||||||
|
@ -27,7 +27,7 @@ int main(int argc, char* argv[]) {
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
|
||||||
int currentExitCode = 0;
|
int currentExitCode = 0;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "IceServer.h"
|
#include "IceServer.h"
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(LogHandler::verboseMessageHandler);
|
||||||
|
|
||||||
IceServer iceServer(argc, argv);
|
IceServer iceServer(argc, argv);
|
||||||
return iceServer.exec();
|
return iceServer.exec();
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
#include <HFActionEvent.h>
|
#include <HFActionEvent.h>
|
||||||
#include <HFBackEvent.h>
|
#include <HFBackEvent.h>
|
||||||
#include <LocalVoxelsList.h>
|
#include <LocalVoxelsList.h>
|
||||||
#include <Logging.h>
|
#include <LogHandler.h>
|
||||||
#include <NetworkAccessManager.h>
|
#include <NetworkAccessManager.h>
|
||||||
#include <OctalCode.h>
|
#include <OctalCode.h>
|
||||||
#include <OctreeSceneStats.h>
|
#include <OctreeSceneStats.h>
|
||||||
|
|
|
@ -19,10 +19,11 @@
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
#include "Assignment.h"
|
#include "Assignment.h"
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
#include "Logging.h"
|
|
||||||
#include "LimitedNodeList.h"
|
#include "LimitedNodeList.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
|
@ -15,10 +15,11 @@
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
#include "Assignment.h"
|
#include "Assignment.h"
|
||||||
#include "HifiSockAddr.h"
|
#include "HifiSockAddr.h"
|
||||||
#include "Logging.h"
|
|
||||||
#include "NodeList.h"
|
#include "NodeList.h"
|
||||||
#include "PacketHeaders.h"
|
#include "PacketHeaders.h"
|
||||||
#include "SharedUtil.h"
|
#include "SharedUtil.h"
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
#include <QtCore/QTimer>
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
#include "Logging.h"
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "ThreadedAssignment.h"
|
#include "ThreadedAssignment.h"
|
||||||
|
|
||||||
ThreadedAssignment::ThreadedAssignment(const QByteArray& packet) :
|
ThreadedAssignment::ThreadedAssignment(const QByteArray& packet) :
|
||||||
|
@ -54,7 +55,7 @@ void ThreadedAssignment::setFinished(bool isFinished) {
|
||||||
|
|
||||||
void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeType, bool shouldSendStats) {
|
void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeType, bool shouldSendStats) {
|
||||||
// change the logging target name while the assignment is running
|
// change the logging target name while the assignment is running
|
||||||
Logging::setTargetName(targetName);
|
LogHandler::getInstance().setTargetName(targetName);
|
||||||
|
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
nodeList->setOwnerType(nodeType);
|
nodeList->setOwnerType(nodeType);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
//
|
//
|
||||||
// Logging.cpp
|
// LogHandler.cpp
|
||||||
// libraries/networking/src
|
// libraries/shared/src
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 6/11/13.
|
// Created by Stephen Birarda on 2014-10-28.
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
// Migrated from Logging.cpp created on 6/11/13
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// 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
|
||||||
|
@ -18,19 +19,17 @@
|
||||||
|
|
||||||
#include <qtimer.h>
|
#include <qtimer.h>
|
||||||
|
|
||||||
#include "Logging.h"
|
#include "LogHandler.h"
|
||||||
|
|
||||||
QString Logging::_targetName = QString();
|
LogHandler& LogHandler::getInstance() {
|
||||||
|
static LogHandler staticInstance;
|
||||||
Logging& Logging::getInstance() {
|
|
||||||
static Logging staticInstance;
|
|
||||||
return staticInstance;
|
return staticInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging::Logging() {
|
LogHandler::LogHandler() {
|
||||||
// setup our timer to flush the verbose logs every 5 seconds
|
// setup our timer to flush the verbose logs every 5 seconds
|
||||||
QTimer* logFlushTimer = new QTimer(this);
|
QTimer* logFlushTimer = new QTimer(this);
|
||||||
connect(logFlushTimer, &QTimer::timeout, this, &Logging::flushRepeatedMessages);
|
connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages);
|
||||||
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ const char* stringForLogType(QtMsgType msgType) {
|
||||||
// the following will produce 2000-10-02 13:55:36 -0700
|
// the following will produce 2000-10-02 13:55:36 -0700
|
||||||
const char DATE_STRING_FORMAT[] = "%Y-%m-%d %H:%M:%S %z";
|
const char DATE_STRING_FORMAT[] = "%Y-%m-%d %H:%M:%S %z";
|
||||||
|
|
||||||
void Logging::verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
if (message.isEmpty()) {
|
if (message.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,9 +86,11 @@ void Logging::verboseMessageHandler(QtMsgType type, const QMessageLogContext& co
|
||||||
fprintf(stdout, "%s %s\n", prefixString.toLocal8Bit().constData(), message.toLocal8Bit().constData());
|
fprintf(stdout, "%s %s\n", prefixString.toLocal8Bit().constData(), message.toLocal8Bit().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logging::flushRepeatedMessages() {
|
void LogHandler::flushRepeatedMessages() {
|
||||||
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
||||||
while (message != _repeatMessageCountHash.end()) {
|
while (message != _repeatMessageCountHash.end()) {
|
||||||
message = _repeatMessageCountHash.erase(message);
|
message = _repeatMessageCountHash.erase(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
//
|
//
|
||||||
// Logging.h
|
// LogHandler.cpp
|
||||||
// libraries/networking/src
|
// libraries/shared/src
|
||||||
//
|
//
|
||||||
// Created by Stephen Birarda on 6/11/13.
|
// Created by Stephen Birarda on 2014-10-28.
|
||||||
// Copyright 2013 High Fidelity, Inc.
|
// Migrated from Logging.cpp created on 6/11/13
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// 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
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef hifi_Logging_h
|
#ifndef hifi_LogHandler_h
|
||||||
#define hifi_Logging_h
|
#define hifi_LogHandler_h
|
||||||
|
|
||||||
#include <qhash.h>
|
#include <qhash.h>
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
|
@ -21,27 +22,28 @@
|
||||||
const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
|
const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
|
||||||
|
|
||||||
/// Handles custom message handling and sending of stats/logs to Logstash instance
|
/// Handles custom message handling and sending of stats/logs to Logstash instance
|
||||||
class Logging : public QObject {
|
class LogHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
static LogHandler& getInstance();
|
||||||
|
|
||||||
/// sets the target name to output via the verboseMessageHandler, called once before logging begins
|
/// sets the target name to output via the verboseMessageHandler, called once before logging begins
|
||||||
/// \param targetName the desired target name to output in logs
|
/// \param targetName the desired target name to output in logs
|
||||||
static void setTargetName(const QString& targetName) { _targetName = targetName; }
|
void setTargetName(const QString& targetName) { _targetName = targetName; }
|
||||||
|
|
||||||
/// a qtMessageHandler that can be hooked up to a target that links to Qt
|
/// a qtMessageHandler that can be hooked up to a target that links to Qt
|
||||||
/// prints various process, message type, and time information
|
/// prints various process, message type, and time information
|
||||||
static void verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message);
|
static void verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &message);
|
||||||
|
|
||||||
static void addRepeatedMessageRegex(const QRegExp& regex) { getInstance()._repeatedMessageRegexes.append(regex); }
|
void addRepeatedMessageRegex(const QRegExp& regex) { _repeatedMessageRegexes.append(regex); }
|
||||||
private:
|
private:
|
||||||
static Logging& getInstance();
|
LogHandler();
|
||||||
Logging();
|
|
||||||
|
|
||||||
void flushRepeatedMessages();
|
void flushRepeatedMessages();
|
||||||
|
|
||||||
static QString _targetName;
|
QString _targetName;
|
||||||
QList<QRegExp> _repeatedMessageRegexes;
|
QList<QRegExp> _repeatedMessageRegexes;
|
||||||
QHash<QString, int> _repeatMessageCountHash;
|
QHash<QString, int> _repeatMessageCountHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Logging_h
|
#endif // hifi_LogHandler_h
|
Loading…
Reference in a new issue