mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 11:10:03 +02:00
Conflicts: assignment-client/src/audio/AudioMixer.cpp domain-server/src/DomainServer.cpp interface/src/Audio.cpp interface/src/DataServerClient.cpp interface/src/Oscilloscope.cpp interface/src/PairingHandler.cpp interface/src/Util.cpp interface/src/avatar/MyAvatar.cpp interface/src/devices/Faceshift.cpp interface/src/devices/SerialInterface.cpp interface/src/renderer/FBXReader.cpp libraries/avatars/src/AvatarData.h libraries/octree-server/src/OctreeServer.cpp libraries/octree-server/src/OctreeServer.h libraries/octree/src/ViewFrustum.cpp libraries/shared/src/Logging.cpp libraries/shared/src/Node.cpp libraries/shared/src/Node.h libraries/shared/src/NodeList.cpp libraries/shared/src/NodeList.h libraries/shared/src/PerfStat.cpp libraries/shared/src/SharedUtil.cpp libraries/voxels/src/VoxelTree.cpp voxel-edit/src/main.cpp
129 lines
No EOL
3.7 KiB
C++
129 lines
No EOL
3.7 KiB
C++
//
|
|
// Logging.cpp
|
|
// hifi
|
|
//
|
|
// Created by Stephen Birarda on 6/11/13.
|
|
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
|
//
|
|
|
|
#include <cstring>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <ctime>
|
|
//#include <netdb.h> // not available on windows, apparently not needed on mac
|
|
|
|
#ifdef _WIN32
|
|
#include <process.h>
|
|
#define getpid _getpid
|
|
#define getppid _getpid // hack to build
|
|
#define pid_t int // hack to build
|
|
#endif
|
|
|
|
#include <QtNetwork/QHostInfo>
|
|
|
|
#include "HifiSockAddr.h"
|
|
#include "SharedUtil.h"
|
|
#include "NodeList.h"
|
|
|
|
#include "Logging.h"
|
|
|
|
HifiSockAddr Logging::logstashSocket = HifiSockAddr();
|
|
char* Logging::targetName = NULL;
|
|
|
|
const HifiSockAddr& Logging::socket() {
|
|
|
|
if (logstashSocket.getAddress().isNull()) {
|
|
// we need to construct the socket object
|
|
// use the constant port
|
|
logstashSocket.setPort(htons(LOGSTASH_UDP_PORT));
|
|
|
|
// lookup the IP address for the constant hostname
|
|
QHostInfo hostInfo = QHostInfo::fromName(LOGSTASH_HOSTNAME);
|
|
if (!hostInfo.addresses().isEmpty()) {
|
|
// use the first IP address
|
|
logstashSocket.setAddress(hostInfo.addresses().first());
|
|
} else {
|
|
printf("Failed to lookup logstash IP - will try again on next log attempt.\n");
|
|
}
|
|
}
|
|
|
|
return logstashSocket;
|
|
}
|
|
|
|
bool Logging::shouldSendStats() {
|
|
static bool shouldSendStats = isInEnvironment("production");
|
|
return shouldSendStats;
|
|
}
|
|
|
|
void Logging::stashValue(char statType, const char* key, float value) {
|
|
static char logstashPacket[MAX_PACKET_SIZE];
|
|
|
|
// load up the logstash packet with the key and the passed float value
|
|
// send it to 4 decimal places
|
|
int numPacketBytes = sprintf(logstashPacket, "%c %s %.4f", statType, key, value);
|
|
|
|
NodeList *nodeList = NodeList::getInstance();
|
|
|
|
if (nodeList) {
|
|
nodeList->getNodeSocket().writeDatagram(logstashPacket, numPacketBytes,
|
|
logstashSocket.getAddress(), logstashSocket.getPort());
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
const char* stringForLogType(QtMsgType msgType) {
|
|
switch (msgType) {
|
|
case QtDebugMsg:
|
|
return "DEBUG";
|
|
case QtCriticalMsg:
|
|
return "CRITICAL";
|
|
case QtFatalMsg:
|
|
return "FATAL";
|
|
case QtWarningMsg:
|
|
return "WARNING";
|
|
default:
|
|
return "UNKNOWN";
|
|
}
|
|
}
|
|
|
|
// the following will produce 2000-10-02 13:55:36 -0700
|
|
const char DATE_STRING_FORMAT[] = "%F %H:%M:%S %z";
|
|
|
|
void Logging::verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
|
// log prefix is in the following format
|
|
// [DEBUG] [TIMESTAMP] [PID:PARENT_PID] [TARGET] logged string
|
|
|
|
QString prefixString = QString("[%1]").arg(stringForLogType(type));
|
|
|
|
time_t rawTime;
|
|
time(&rawTime);
|
|
struct tm* localTime = localtime(&rawTime);
|
|
|
|
char dateString[100];
|
|
strftime(dateString, sizeof(dateString), DATE_STRING_FORMAT, localTime);
|
|
|
|
prefixString.append(QString(" [%1]").arg(dateString));
|
|
|
|
prefixString.append(QString(" [%1").arg(getpid()));
|
|
|
|
pid_t parentProcessID = getppid();
|
|
if (parentProcessID != 0) {
|
|
prefixString.append(QString(":%1]").arg(parentProcessID));
|
|
} else {
|
|
prefixString.append("]");
|
|
}
|
|
|
|
if (Logging::targetName) {
|
|
prefixString.append(QString(" [%1]").arg(Logging::targetName));
|
|
}
|
|
|
|
fprintf(stdout, "%s %s\n", prefixString.toLocal8Bit().constData(), message.toLocal8Bit().constData());
|
|
} |