Created logger with log levels

This commit is contained in:
Diego Waxemberg
2015-02-10 21:26:55 -05:00
parent 0c36754ebe
commit e3dd4e7238
26 changed files with 182 additions and 113 deletions

View File

@@ -32,7 +32,7 @@
Host* oldHost = _host;
_host = host;
BOOL useCache = [oldHost.uuid isEqualToString:_host.uuid];
NSLog(@"Using cached app images: %d", useCache);
Log(LOG_I, @"Using cached app images: %d", useCache);
if (!useCache) {
[_imageCache removeAllObjects];
}

View File

@@ -29,13 +29,13 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
- (void) parseData {
xmlDocPtr docPtr = xmlParseMemory([self.data bytes], (int)[self.data length]);
if (docPtr == NULL) {
NSLog(@"ERROR: An error occured trying to parse xml.");
Log(LOG_W, @"An error occured trying to parse xml.");
return;
}
xmlNodePtr node = xmlDocGetRootElement(docPtr);
if (node == NULL) {
NSLog(@"ERROR: No root XML element.");
Log(LOG_W, @"No root XML element.");
xmlFreeDoc(docPtr);
return;
}
@@ -61,7 +61,7 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
node = node->children;
while (node != NULL) {
//NSLog(@"node: %s", node->name);
//Log(LOG_D, @"node: %s", node->name);
if (!xmlStrcmp(node->name, (xmlChar*)TAG_APP)) {
xmlNodePtr appInfoNode = node->xmlChildrenNode;
NSString* appName;

View File

@@ -63,7 +63,7 @@
}
- (void) startDiscovery {
NSLog(@"Starting discovery");
Log(LOG_I, @"Starting discovery");
shouldDiscover = YES;
[_mdnsMan searchForHosts];
for (Host* host in _hostQueue) {
@@ -72,19 +72,19 @@
}
- (void) stopDiscovery {
NSLog(@"Stopping discovery");
Log(LOG_I, @"Stopping discovery");
shouldDiscover = NO;
[_mdnsMan stopSearching];
[_opQueue cancelAllOperations];
}
- (void) stopDiscoveryBlocking {
NSLog(@"Stopping discovery and waiting for workers to stop");
Log(LOG_I, @"Stopping discovery and waiting for workers to stop");
shouldDiscover = NO;
[_mdnsMan stopSearching];
[_opQueue cancelAllOperations];
[_opQueue waitUntilAllOperationsAreFinished];
NSLog(@"All discovery workers stopped");
Log(LOG_I, @"All discovery workers stopped");
}
- (BOOL) addHostToDiscovery:(Host *)host {
@@ -113,15 +113,15 @@
DataManager* dataMan = [[DataManager alloc] init];
// Discover the hosts before adding to eliminate duplicates
for (Host* host in hosts) {
NSLog(@"Found host through MDNS: %@:", host.name);
Log(LOG_I, @"Found host through MDNS: %@:", host.name);
// Since this is on a background thread, we do not need to use the opQueue
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
[worker discoverHost];
if ([self addHostToDiscovery:host]) {
NSLog(@"Adding host to discovery: %@", host.name);
Log(LOG_I, @"Adding host to discovery: %@", host.name);
[_callback updateAllHosts:_hostQueue];
} else {
NSLog(@"Not adding host to discovery: %@", host.name);
Log(LOG_I, @"Not adding host to discovery: %@", host.name);
[dataMan removeHost:host];
}
}

View File

@@ -57,7 +57,7 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
}
_host.online = receivedResponse;
if (receivedResponse) {
NSLog(@"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.uuid, _host.mac, _host.pairState, _host.online);
Log(LOG_D, @"Received response from: %@\n{\n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n}", _host.name, _host.address, _host.localAddress, _host.externalAddress, _host.uuid, _host.mac, _host.pairState, _host.online);
}
}
@@ -79,7 +79,7 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
[response populateHost:_host];
return YES;
} else {
NSLog(@"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid);
Log(LOG_I, @"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid);
}
}
return NO;

View File

@@ -48,7 +48,7 @@ static const NSString* PORT = @"47984";
}
- (void) executeRequestSynchronously:(HttpRequest*)request {
NSLog(@"Making Request: %@", request);
Log(LOG_D, @"Making Request: %@", request);
[_respData setLength:0];
dispatch_sync(dispatch_get_main_queue(), ^{
[NSURLConnection connectionWithRequest:request.request delegate:self];
@@ -154,11 +154,11 @@ static const NSString* PORT = @"47984";
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"Received response: %@", response);
Log(LOG_D, @"Received response: %@", response);
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"\n\nReceived data: %@\n\n", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
Log(LOG_D, @"\n\nReceived data: %@\n\n", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
[_respData appendData:data];
}
@@ -202,11 +202,11 @@ static const NSString* PORT = @"47984";
OSStatus securityError = SecPKCS12Import(p12Data, options, &items);
if (securityError == errSecSuccess) {
//NSLog(@"Success opening p12 certificate. Items: %ld", CFArrayGetCount(items));
//Log(LOG_D, @"Success opening p12 certificate. Items: %ld", CFArrayGetCount(items));
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
identityApp = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity);
} else {
NSLog(@"Error opening Certificate.");
Log(LOG_E, @"Error opening Certificate.");
}
CFRelease(options);
@@ -216,7 +216,7 @@ static const NSString* PORT = @"47984";
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"connection error: %@", error);
Log(LOG_W, @"connection error: %@", error);
dispatch_semaphore_signal(_requestLock);
}

View File

@@ -42,13 +42,13 @@
_elements = [[NSMutableDictionary alloc] init];
xmlDocPtr docPtr = xmlParseMemory([self.data bytes], (int)[self.data length]);
if (docPtr == NULL) {
NSLog(@"ERROR: An error occured trying to parse xml.");
Log(LOG_W, @"An error occured trying to parse xml.");
return;
}
xmlNodePtr node = xmlDocGetRootElement(docPtr);
if (node == NULL) {
NSLog(@"ERROR: No root XML element.");
Log(LOG_W, @"No root XML element.");
xmlFreeDoc(docPtr);
return;
}

View File

@@ -34,13 +34,13 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
}
- (void) searchForHosts {
NSLog(@"Starting mDNS discovery");
Log(LOG_I, @"Starting mDNS discovery");
scanActive = TRUE;
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
}
- (void) stopSearching {
NSLog(@"Stopping mDNS discovery");
Log(LOG_I, @"Stopping mDNS discovery");
scanActive = FALSE;
[mDNSBrowser stop];
}
@@ -60,12 +60,12 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
}
- (void)netServiceDidResolveAddress:(NSNetService *)service {
NSLog(@"Resolved address: %@ -> %@", service, service.hostName);
Log(LOG_I, @"Resolved address: %@ -> %@", service, service.hostName);
[self.callback updateHosts:[self getFoundHosts]];
}
- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict {
NSLog(@"Did not resolve address for: %@\n%@", sender, [errorDict description]);
Log(LOG_W, @"Did not resolve address for: %@\n%@", sender, [errorDict description]);
// Schedule a retry in 2 seconds
[NSTimer scheduledTimerWithTimeInterval:2.0
@@ -76,7 +76,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
NSLog(@"Found service: %@", aNetService);
Log(LOG_I, @"Found service: %@", aNetService);
[aNetService setDelegate:self];
[aNetService resolveWithTimeout:5];
@@ -85,13 +85,12 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didRemoveService:(NSNetService *)aNetService moreComing:(BOOL)moreComing {
NSLog(@"Removing service: %@", aNetService);
Log(LOG_I, @"Removing service: %@", aNetService);
[services removeObject:aNetService];
}
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didNotSearch:(NSDictionary *)errorDict {
NSLog(@"Did not perform search");
NSLog(@"%@", [errorDict description]);
Log(LOG_W, @"Did not perform search: \n%@", [errorDict description]);
// Schedule a retry in 2 seconds
[NSTimer scheduledTimerWithTimeInterval:2.0
@@ -107,7 +106,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
return;
}
NSLog(@"Retrying mDNS search");
Log(LOG_I, @"Retrying mDNS search");
[mDNSBrowser stop];
[mDNSBrowser searchForServicesOfType:NV_SERVICE_TYPE inDomain:@""];
}
@@ -118,7 +117,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
return;
}
NSLog(@"Retrying mDNS resolution");
Log(LOG_I, @"Retrying mDNS resolution");
for (NSNetService* service in services) {
if (service.hostName == nil) {
[service setDelegate:self];

View File

@@ -50,7 +50,7 @@
- (void) initiatePair {
NSString* PIN = [self generatePIN];
NSData* salt = [self saltPIN:PIN];
NSLog(@"PIN: %@, saltedPIN: %@", PIN, salt);
Log(LOG_I, @"PIN: %@, saltedPIN: %@", PIN, salt);
[_callback showPIN:PIN];
HttpResponse* pairResp = [[HttpResponse alloc] init];

View File

@@ -24,10 +24,10 @@ static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
CFSocketRef wolSocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, NULL);
if (!wolSocket) {
CFRelease(dataPayload);
NSLog(@"Failed to create WOL socket");
Log(LOG_E, @"Failed to create WOL socket");
return;
}
NSLog(@"WOL socket created");
Log(LOG_I, @"WOL socket created");
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
@@ -48,7 +48,7 @@ static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
// try all ports
for (int j = 0; j < numPorts; j++) {
addr.sin_port = htons(ports[j]);
NSLog(@"Sending WOL packet");
Log(LOG_I, @"Sending WOL packet");
CFSocketSendData(wolSocket, dataAddress, dataPayload, 0);
}
CFRelease(dataAddress);
@@ -76,7 +76,7 @@ static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
+ (NSData*) macStringToBytes:(NSString*)mac {
NSString* macString = [mac stringByReplacingOccurrencesOfString:@":" withString:@""];
NSLog(@"MAC: %@", macString);
Log(LOG_D, @"MAC: %@", macString);
return [Utils hexToBytes:macString];
}