mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 01:22:08 +02:00
add a static method to the Logging class to change target name
This commit is contained in:
parent
8077963bb1
commit
fe8fabee38
3 changed files with 32 additions and 15 deletions
|
@ -61,18 +61,20 @@ void childClient() {
|
|||
if (nodeList->getNodeSocket()->receive(packetData, &receivedBytes) &&
|
||||
packetData[0] == PACKET_TYPE_DEPLOY_ASSIGNMENT && packetVersionMatch(packetData)) {
|
||||
|
||||
// reset the logging target to the the CHILD_TARGET_NAME
|
||||
Logging::setTargetName(CHILD_TARGET_NAME);
|
||||
|
||||
// construct the deployed assignment from the packet data
|
||||
Assignment deployedAssignment(packetData, receivedBytes);
|
||||
|
||||
Logging::standardizedLog(QString("Received an assignment - %1").arg(deployedAssignment.toString()),
|
||||
CHILD_TARGET_NAME);
|
||||
Logging::standardizedLog(QString("Received an assignment - %1").arg(deployedAssignment.toString()));
|
||||
|
||||
// switch our nodelist DOMAIN_IP to the ip receieved in the assignment
|
||||
if (deployedAssignment.getDomainSocket()->sa_family == AF_INET) {
|
||||
in_addr domainSocketAddr = ((sockaddr_in*) deployedAssignment.getDomainSocket())->sin_addr;
|
||||
nodeList->setDomainIP(inet_ntoa(domainSocketAddr));
|
||||
|
||||
Logging::standardizedLog(QString("Changed Domain IP to %1").arg(inet_ntoa(domainSocketAddr)), CHILD_TARGET_NAME);
|
||||
Logging::standardizedLog(QString("Changed Domain IP to %1").arg(inet_ntoa(domainSocketAddr)));
|
||||
}
|
||||
|
||||
if (deployedAssignment.getType() == Assignment::AudioMixer) {
|
||||
|
@ -81,8 +83,7 @@ void childClient() {
|
|||
AvatarMixer::run();
|
||||
}
|
||||
|
||||
Logging::standardizedLog(QString("Assignment finished or never started - waiting for new assignment"),
|
||||
CHILD_TARGET_NAME);
|
||||
Logging::standardizedLog(QString("Assignment finished or never started - waiting for new assignment"));
|
||||
|
||||
// reset our NodeList by switching back to unassigned and clearing the list
|
||||
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
||||
|
@ -118,8 +119,7 @@ void sigchldHandler(int sig) {
|
|||
// this is the parent, replace the dead process with the new one
|
||||
::childForks[i] = newForkProcessID;
|
||||
|
||||
Logging::standardizedLog(QString("Repleaced dead %1 with new fork %2").arg(processID).arg(newForkProcessID),
|
||||
PARENT_TARGET_NAME);
|
||||
Logging::standardizedLog(QString("Replaced dead %1 with new fork %2").arg(processID).arg(newForkProcessID));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -154,6 +154,9 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
// start the Logging class with the parent's target name
|
||||
Logging::setTargetName(PARENT_TARGET_NAME);
|
||||
|
||||
// grab the overriden assignment-server hostname from argv, if it exists
|
||||
const char* customAssignmentServer = getCmdOption(argc, argv, "-a");
|
||||
if (customAssignmentServer) {
|
||||
|
@ -171,7 +174,7 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
if (numForksString) {
|
||||
::numForks = atoi(numForksString);
|
||||
Logging::standardizedLog(QString("Starting %1 assignment clients").arg(numForks), PARENT_TARGET_NAME);
|
||||
Logging::standardizedLog(QString("Starting %1 assignment clients").arg(numForks));
|
||||
|
||||
::childForks = new pid_t[numForks];
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "Logging.h"
|
||||
|
||||
sockaddr_in Logging::logstashSocket = {};
|
||||
char* Logging::targetName = NULL;
|
||||
|
||||
sockaddr* Logging::socket() {
|
||||
|
||||
|
@ -73,10 +74,19 @@ const QString& stringForLogType(Logging::Type logType) {
|
|||
}
|
||||
}
|
||||
|
||||
void Logging::setTargetName(const char* targetName) {
|
||||
// remove the old target name, if it exists
|
||||
delete Logging::targetName;
|
||||
|
||||
// copy over the new target name
|
||||
Logging::targetName = new char[strlen(targetName)];
|
||||
strcpy(Logging::targetName, targetName);
|
||||
}
|
||||
|
||||
// the following will produce 2000-10-02 13:55:36 -0700
|
||||
const char DATE_STRING_FORMAT[] = "%F %H:%M:%S %z";
|
||||
|
||||
void Logging::standardizedLog(const QString &output, const char* targetName, Logging::Type logType) {
|
||||
void Logging::standardizedLog(const QString &output, Logging::Type logType) {
|
||||
time_t rawTime;
|
||||
time(&rawTime);
|
||||
struct tm* localTime = localtime(&rawTime);
|
||||
|
@ -84,23 +94,25 @@ void Logging::standardizedLog(const QString &output, const char* targetName, Log
|
|||
// log prefix is in the following format
|
||||
// [DEBUG] [TIMESTAMP] [PID:PARENT_PID] [TARGET] logged string
|
||||
|
||||
QString prefixString = QString("[%1] ").arg(stringForLogType(logType));
|
||||
QString prefixString = QString("[%1]").arg(stringForLogType(logType));
|
||||
|
||||
char dateString[100];
|
||||
strftime(dateString, sizeof(dateString), DATE_STRING_FORMAT, localTime);
|
||||
|
||||
prefixString.append(QString("[%1] ").arg(dateString));
|
||||
prefixString.append(QString(" [%1]").arg(dateString));
|
||||
|
||||
prefixString.append(QString("[%1").arg(getpid()));
|
||||
prefixString.append(QString(" [%1").arg(getpid()));
|
||||
|
||||
pid_t parentProcessID = getppid();
|
||||
if (parentProcessID != 0) {
|
||||
prefixString.append(QString(":%1] ").arg(parentProcessID));
|
||||
prefixString.append(QString(":%1]").arg(parentProcessID));
|
||||
} else {
|
||||
prefixString.append("]");
|
||||
}
|
||||
|
||||
prefixString.append(QString("[%1]").arg(targetName));
|
||||
if (Logging::targetName) {
|
||||
prefixString.append(QString(" [%1]").arg(Logging::targetName));
|
||||
}
|
||||
|
||||
qDebug("%s %s", prefixString.toStdString().c_str(), output.toStdString().c_str());
|
||||
}
|
|
@ -32,9 +32,11 @@ public:
|
|||
static sockaddr* socket();
|
||||
static bool shouldSendStats();
|
||||
static void stashValue(char statType, const char* key, float value);
|
||||
static void standardizedLog(const QString& output, const char* targetName, Logging::Type logType = Logging::Debug);
|
||||
static void setTargetName(const char* targetName);
|
||||
static void standardizedLog(const QString& output, Logging::Type logType = Logging::Debug);
|
||||
private:
|
||||
static sockaddr_in logstashSocket;
|
||||
static char* targetName;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__Logstash__) */
|
||||
|
|
Loading…
Reference in a new issue