mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 19:55:07 +02:00
integrates logging for 'shared' library
This commit is contained in:
parent
349e89aaa6
commit
e55863a662
11 changed files with 103 additions and 30 deletions
|
@ -144,10 +144,7 @@ inline void Log::addMessage(char const* ptr) {
|
|||
|
||||
}
|
||||
|
||||
void Log::operator()(char const* fmt, ...) {
|
||||
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
int Log::vprint(char const* fmt, va_list args) {
|
||||
pthread_mutex_lock(& _mtx);
|
||||
|
||||
// print to buffer
|
||||
|
@ -166,6 +163,14 @@ void Log::operator()(char const* fmt, ...) {
|
|||
}
|
||||
|
||||
pthread_mutex_unlock(& _mtx);
|
||||
return n;
|
||||
}
|
||||
|
||||
void Log::operator()(char const* fmt, ...) {
|
||||
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
vprint(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
@ -304,8 +309,13 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) {
|
|||
glMatrixMode(matrixMode);
|
||||
}
|
||||
|
||||
Log printLog;
|
||||
|
||||
Log logger;
|
||||
|
||||
int printLog(char const* fmt, ...) {
|
||||
|
||||
va_list args;
|
||||
va_start(args,fmt);
|
||||
logger.vprint(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define __interface__Log__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <pthread.h>
|
||||
|
||||
|
@ -18,7 +19,13 @@ class Log;
|
|||
//
|
||||
// Call it as you would call 'printf'.
|
||||
//
|
||||
extern Log printLog;
|
||||
int printLog(char const* fmt, ...);
|
||||
|
||||
//
|
||||
// Global instance.
|
||||
//
|
||||
extern Log logger;
|
||||
|
||||
|
||||
//
|
||||
// Logging subsystem.
|
||||
|
@ -57,6 +64,7 @@ public:
|
|||
void render(unsigned screenWidth, unsigned screenHeight);
|
||||
|
||||
void operator()(char const* fmt, ...);
|
||||
int vprint(char const* fmt, va_list);
|
||||
|
||||
private:
|
||||
// don't copy/assign
|
||||
|
|
|
@ -889,7 +889,7 @@ void display(void)
|
|||
glLineWidth(1.0f);
|
||||
glPointSize(1.0f);
|
||||
displayStats();
|
||||
printLog.render(WIDTH, HEIGHT);
|
||||
logger.render(WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
// Show menu
|
||||
|
@ -1514,6 +1514,9 @@ void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
|||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
shared::printLog = ::printLog;
|
||||
|
||||
|
||||
// Quick test of the Orientation class on startup!
|
||||
testOrientationClass();
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
using shared::printLog;
|
||||
|
||||
const char * SOLO_AGENT_TYPES_STRING = "MV";
|
||||
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
|
||||
char DOMAIN_IP[100] = ""; // IP Address will be re-set by lookup on startup
|
||||
|
@ -37,7 +39,7 @@ AgentList* AgentList::createInstance(char ownerType, unsigned int socketListenPo
|
|||
if (_sharedInstance == NULL) {
|
||||
_sharedInstance = new AgentList(ownerType, socketListenPort);
|
||||
} else {
|
||||
printf("AgentList createInstance called with existing instance.\n");
|
||||
printLog("AgentList createInstance called with existing instance.\n");
|
||||
}
|
||||
|
||||
return _sharedInstance;
|
||||
|
@ -45,7 +47,7 @@ AgentList* AgentList::createInstance(char ownerType, unsigned int socketListenPo
|
|||
|
||||
AgentList* AgentList::getInstance() {
|
||||
if (_sharedInstance == NULL) {
|
||||
printf("AgentList getInstance called before call to createInstance. Returning NULL pointer.\n");
|
||||
printLog("AgentList getInstance called before call to createInstance. Returning NULL pointer.\n");
|
||||
}
|
||||
|
||||
return _sharedInstance;
|
||||
|
@ -391,12 +393,12 @@ void *checkInWithDomainServer(void *args) {
|
|||
sockaddr_in tempAddress;
|
||||
memcpy(&tempAddress.sin_addr, pHostInfo->h_addr_list[0], pHostInfo->h_length);
|
||||
strcpy(DOMAIN_IP, inet_ntoa(tempAddress.sin_addr));
|
||||
printf("Domain server: %s \n", DOMAIN_HOSTNAME);
|
||||
printLog("Domain server: %s \n", DOMAIN_HOSTNAME);
|
||||
|
||||
} else {
|
||||
printf("Failed lookup domainserver\n");
|
||||
printLog("Failed lookup domainserver\n");
|
||||
}
|
||||
} else printf("Using static domainserver IP: %s\n", DOMAIN_IP);
|
||||
} else printLog("Using static domainserver IP: %s\n", DOMAIN_IP);
|
||||
|
||||
|
||||
while (!domainServerCheckinStopFlag) {
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "shared_Log.h"
|
||||
#include "Agent.h"
|
||||
#include "UDPSocket.h"
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#endif
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "shared_Log.h"
|
||||
|
||||
//private:
|
||||
// long int currentCount;
|
||||
|
@ -98,7 +98,7 @@ void CounterStatHistory::recordSample(double thisTime, long thisCount) {
|
|||
this->currentTime = thisTime;
|
||||
this->currentDelta = thisDelta;
|
||||
|
||||
//printf("CounterStatHistory[%s]::recordSample(thisTime %lf, thisCount= %ld)\n",this->name.c_str(),thisTime,thisCount);
|
||||
//printLog("CounterStatHistory[%s]::recordSample(thisTime %lf, thisCount= %ld)\n",this->name.c_str(),thisTime,thisCount);
|
||||
|
||||
// if more than 1/10th of a second has passed, then record
|
||||
// things in our rolling history
|
||||
|
@ -115,7 +115,7 @@ void CounterStatHistory::recordSample(double thisTime, long thisCount) {
|
|||
this->timeSamples[this->sampleAt]=thisTime;
|
||||
this->deltaSamples[this->sampleAt]=thisDelta;
|
||||
|
||||
//printf("CounterStatHistory[%s]::recordSample() ACTUALLY RECORDING IT sampleAt=%d thisTime %lf, thisCount= %ld)\n",this->name.c_str(),this->sampleAt,thisTime,thisCount);
|
||||
//printLog("CounterStatHistory[%s]::recordSample() ACTUALLY RECORDING IT sampleAt=%d thisTime %lf, thisCount= %ld)\n",this->name.c_str(),this->sampleAt,thisTime,thisCount);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "shared_Log.h"
|
||||
|
||||
using shared::printLog;
|
||||
|
||||
// Static class members initialization here!
|
||||
std::map<std::string,PerfStatHistory,std::less<std::string> > PerfStat::groupHistoryMap;
|
||||
bool PerfStat::wantDebugOut = false;
|
||||
|
@ -55,7 +59,7 @@ PerfStat::~PerfStat() {
|
|||
}
|
||||
|
||||
if (wantDebugOut) {
|
||||
printf("PerfStats: %s elapsed:%f average:%lf count:%ld total:%lf ut:%d us:%d ue:%d t:%ld s:%ld e:%ld\n",
|
||||
printLog("PerfStats: %s elapsed:%f average:%lf count:%ld total:%lf ut:%d us:%d ue:%d t:%ld s:%ld e:%ld\n",
|
||||
this->group.c_str(),elapsed,average,count,totalTime,
|
||||
(end.tv_usec-start.tv_usec),start.tv_usec,end.tv_usec,
|
||||
(end.tv_sec-start.tv_sec),start.tv_sec,end.tv_sec
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#ifdef _WIN32
|
||||
#include "Syssocket.h"
|
||||
#endif
|
||||
#include "shared_Log.h"
|
||||
#include "SharedUtil.h"
|
||||
#include "OctalCode.h"
|
||||
|
||||
|
@ -19,6 +20,8 @@
|
|||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
using shared::printLog;
|
||||
|
||||
double usecTimestamp(timeval *time) {
|
||||
return (time->tv_sec * 1000000.0 + time->tv_usec);
|
||||
}
|
||||
|
@ -50,13 +53,13 @@ bool randomBoolean() {
|
|||
}
|
||||
|
||||
void outputBits(unsigned char byte) {
|
||||
printf("%d: ", byte);
|
||||
printLog("%d: ", byte);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
printf("%d", byte >> (7 - i) & 1);
|
||||
printLog("%d", byte >> (7 - i) & 1);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printLog("\n");
|
||||
}
|
||||
|
||||
int numberOfOnes(unsigned char byte) {
|
||||
|
@ -328,14 +331,14 @@ void printVoxelCode(unsigned char* voxelCode) {
|
|||
unsigned int voxelSizeInOctets = (voxelSizeInBits/3);
|
||||
unsigned int voxelBufferSize = voxelSizeInBytes+1+3; // 1 for size, 3 for color
|
||||
|
||||
printf("octets=%d\n",octets);
|
||||
printf("voxelSizeInBits=%d\n",voxelSizeInBits);
|
||||
printf("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
||||
printf("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
||||
printf("voxelBufferSize=%d\n",voxelBufferSize);
|
||||
printLog("octets=%d\n",octets);
|
||||
printLog("voxelSizeInBits=%d\n",voxelSizeInBits);
|
||||
printLog("voxelSizeInBytes=%d\n",voxelSizeInBytes);
|
||||
printLog("voxelSizeInOctets=%d\n",voxelSizeInOctets);
|
||||
printLog("voxelBufferSize=%d\n",voxelBufferSize);
|
||||
|
||||
for(int i=0;i<voxelBufferSize;i++) {
|
||||
printf("i=%d ",i);
|
||||
printLog("i=%d ",i);
|
||||
outputBits(voxelCode[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <ifaddrs.h>
|
||||
#endif
|
||||
|
||||
#include "shared_Log.h"
|
||||
|
||||
using shared::printLog;
|
||||
|
||||
sockaddr_in destSockaddr, senderAddress;
|
||||
|
||||
bool socketMatch(sockaddr *first, sockaddr *second) {
|
||||
|
@ -104,7 +108,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
|||
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
if (handle <= 0) {
|
||||
printf("Failed to create socket.\n");
|
||||
printLog("Failed to create socket.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -117,7 +121,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
|||
bind_address.sin_port = htons((uint16_t) listeningPort);
|
||||
|
||||
if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) {
|
||||
printf("Failed to bind socket to port %d.\n", listeningPort);
|
||||
printLog("Failed to bind socket to port %d.\n", listeningPort);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -127,7 +131,7 @@ UDPSocket::UDPSocket(int listeningPort) {
|
|||
tv.tv_usec = 500000;
|
||||
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
||||
|
||||
printf("Created UDP socket listening on port %d.\n", listeningPort);
|
||||
printLog("Created UDP socket listening on port %d.\n", listeningPort);
|
||||
}
|
||||
|
||||
UDPSocket::~UDPSocket() {
|
||||
|
@ -196,7 +200,7 @@ int UDPSocket::send(sockaddr *destAddress, const void *data, size_t byteLength)
|
|||
0, (sockaddr *) destAddress, sizeof(sockaddr_in));
|
||||
|
||||
if (sent_bytes != byteLength) {
|
||||
printf("Failed to send packet: %s\n", strerror(errno));
|
||||
printLog("Failed to send packet: %s\n", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
17
libraries/shared/src/shared_Log.cpp
Normal file
17
libraries/shared/src/shared_Log.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// Log.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Tobias Schwinger on 4/17/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "shared_Log.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace shared {
|
||||
using namespace std;
|
||||
|
||||
int (* printLog)(char const*, ...) = & printf;
|
||||
}
|
20
libraries/shared/src/shared_Log.h
Normal file
20
libraries/shared/src/shared_Log.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// shared_Log.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Tobias Schwinger on 4/17/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__shared_Log__
|
||||
#define __hifi__shared_Log__
|
||||
|
||||
namespace shared {
|
||||
|
||||
// variable that can be set from outside to redirect the log output
|
||||
// of this library
|
||||
extern int (* printLog)(char const*, ...);
|
||||
}
|
||||
|
||||
#endif /* defined(__hifi__shared_Log__) */
|
||||
|
Loading…
Reference in a new issue