more leveraging of standardized logging

This commit is contained in:
Stephen Birarda 2013-09-09 14:47:15 -07:00
parent fe8fabee38
commit b0c9dfeddc
9 changed files with 41 additions and 16 deletions

View file

@ -32,6 +32,9 @@ int numForks = 0;
void childClient() {
// this is one of the child forks or there is a single assignment client, continue assignment-client execution
// set the logging target to the the CHILD_TARGET_NAME
Logging::setTargetName(CHILD_TARGET_NAME);
// create a NodeList as an unassigned client
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
@ -61,8 +64,7 @@ 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);
@ -88,6 +90,9 @@ void childClient() {
// reset our NodeList by switching back to unassigned and clearing the list
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
nodeList->clear();
// reset the logging target to the the CHILD_TARGET_NAME
Logging::setTargetName(CHILD_TARGET_NAME);
}
}
}

View file

@ -57,6 +57,8 @@ const unsigned int BUFFER_SEND_INTERVAL_USECS = floorf((BUFFER_LENGTH_SAMPLES_PE
const int MAX_SAMPLE_VALUE = std::numeric_limits<int16_t>::max();
const int MIN_SAMPLE_VALUE = std::numeric_limits<int16_t>::min();
const char AUDIO_MIXER_LOGGING_TARGET_NAME[] = "audio-mixer";
void attachNewBufferToNode(Node *newNode) {
if (!newNode->getLinkedData()) {
if (newNode->getType() == NODE_TYPE_AGENT) {
@ -68,6 +70,8 @@ void attachNewBufferToNode(Node *newNode) {
}
void AudioMixer::run() {
// change the logging target name while this is running
Logging::setTargetName(AUDIO_MIXER_LOGGING_TARGET_NAME);
NodeList *nodeList = NodeList::getInstance();
nodeList->setOwnerType(NODE_TYPE_AUDIO_MIXER);

View file

@ -10,6 +10,7 @@
// The avatar mixer receives head, hand and positional data from all connected
// nodes, and broadcasts that data back to them, every BROADCAST_INTERVAL ms.
#include <Logging.h>
#include <NodeList.h>
#include <PacketHeaders.h>
#include <SharedUtil.h>
@ -18,6 +19,8 @@
#include "AvatarMixer.h"
const char AVATAR_MIXER_LOGGING_NAME[] = "avatar-mixer";
unsigned char* addNodeToBroadcastPacket(unsigned char *currentPosition, Node *nodeToAdd) {
currentPosition += packNodeId(currentPosition, nodeToAdd->getNodeID());
@ -81,6 +84,9 @@ void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) {
}
void AvatarMixer::run() {
// change the logging target name while AvatarMixer is running
Logging::setTargetName(AVATAR_MIXER_LOGGING_NAME);
NodeList* nodeList = NodeList::getInstance();
nodeList->setOwnerType(NODE_TYPE_AVATAR_MIXER);

View file

@ -86,6 +86,10 @@ void Logging::setTargetName(const char* 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 char *output, Logging::Type logType) {
standardizedLog(QString(output), logType);
}
void Logging::standardizedLog(const QString &output, Logging::Type logType) {
time_t rawTime;
time(&rawTime);

View file

@ -33,6 +33,7 @@ public:
static bool shouldSendStats();
static void stashValue(char statType, const char* key, float value);
static void setTargetName(const char* targetName);
static void standardizedLog(const char* output, Logging::Type logType = Logging::Debug);
static void standardizedLog(const QString& output, Logging::Type logType = Logging::Debug);
private:
static sockaddr_in logstashSocket;

View file

@ -144,14 +144,16 @@ float Node::getAverageKilobitsPerSecond() {
}
}
QDebug operator<<(QDebug debug, const Node &node) {
QString Node::toString() const {
char publicAddressBuffer[16] = {'\0'};
unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, node.getPublicSocket());
unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, _publicSocket);
//char localAddressBuffer[16] = {'\0'};
//unsigned short localAddressPort = loadBufferWithSocketInfo(localAddressBuffer, node.localSocket);
debug << "#" << node.getNodeID() << node.getTypeName() << node.getType();
debug.nospace() << publicAddressBuffer << ":" << publicAddressPort;
return debug.nospace();
return QString("# %1 %2 %3 %4:%5").arg(_nodeID).arg(getTypeName()).arg(_type).arg(publicAddressBuffer).arg(publicAddressPort);
}
QDebug operator<<(QDebug debug, const Node &node) {
return debug << node.toString();
}

View file

@ -72,6 +72,8 @@ public:
void unlock() { pthread_mutex_unlock(&_mutex); }
static void printLog(Node const&);
QString toString() const;
private:
// privatize copy and assignment operator to disallow Node copying
Node(const Node &otherNode);

View file

@ -14,6 +14,7 @@
#include <QtCore/QDebug>
#include "Assignment.h"
#include "Logging.h"
#include "NodeList.h"
#include "NodeTypes.h"
#include "PacketHeaders.h"
@ -43,7 +44,7 @@ NodeList* NodeList::createInstance(char ownerType, unsigned short int socketList
if (!_sharedInstance) {
_sharedInstance = new NodeList(ownerType, socketListenPort);
} else {
qDebug("NodeList createInstance called with existing instance.\n");
Logging::standardizedLog("NodeList createInstance called with existing instance.");
}
return _sharedInstance;
@ -51,7 +52,7 @@ NodeList* NodeList::createInstance(char ownerType, unsigned short int socketList
NodeList* NodeList::getInstance() {
if (!_sharedInstance) {
qDebug("NodeList getInstance called before call to createInstance. Returning NULL pointer.\n");
Logging::standardizedLog("NodeList getInstance called before call to createInstance. Returning NULL pointer.");
}
return _sharedInstance;
@ -278,13 +279,12 @@ void NodeList::sendDomainServerCheckIn() {
sockaddr_in tempAddress;
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
strcpy(_domainIP, inet_ntoa(tempAddress.sin_addr));
qDebug("Domain Server: %s\n", _domainHostname);
Logging::standardizedLog(QString("Domain Server: %1").arg(_domainHostname));
} else {
qDebug("Failed domain server lookup\n");
Logging::standardizedLog("Failed domain server lookup", Logging::Warn);
}
} else if (!printedDomainServerIP) {
qDebug("Domain Server IP: %s\n", _domainIP);
Logging::standardizedLog(QString("Domain Server IP: %1").arg(_domainIP));
printedDomainServerIP = true;
}
@ -460,7 +460,7 @@ void NodeList::addNodeToList(Node* newNode) {
++_numNodes;
qDebug() << "Added" << *newNode << "\n";
Logging::standardizedLog(QString("Added %1").arg(newNode->toString()));
notifyHooksOfAddedNode(newNode);
}
@ -516,7 +516,7 @@ void* removeSilentNodes(void *args) {
if ((checkTimeUSecs - node->getLastHeardMicrostamp()) > NODE_SILENCE_THRESHOLD_USECS) {
qDebug() << "Killed" << *node << "\n";
Logging::standardizedLog(QString("Killed %1").arg(node->toString()));
nodeList->notifyHooksOfKilledNode(&*node);

View file

@ -23,6 +23,7 @@
#include <QtCore/QDebug>
#include "Logging.h"
#include "UDPSocket.h"
sockaddr_in destSockaddr, senderAddress;
@ -170,7 +171,7 @@ UDPSocket::UDPSocket(unsigned short int listeningPort) :
const int DEFAULT_BLOCKING_SOCKET_TIMEOUT_USECS = 0.5 * 1000000;
setBlockingReceiveTimeoutInUsecs(DEFAULT_BLOCKING_SOCKET_TIMEOUT_USECS);
qDebug("Created UDP socket listening on port %hu.\n", _listeningPort);
Logging::standardizedLog(QString("Created UDP Socket listening on %1").arg(_listeningPort));
}
UDPSocket::~UDPSocket() {