From 2c6a6728125d69702b6292a6f99b9e2480bc5571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien-Pierre=20Av=C3=A9rous?= Date: Sun, 14 Aug 2016 04:43:23 +0200 Subject: [PATCH] - Enhance logs. --- .../TorChat/TCConfigurationHelperController.m | 12 +++++++----- TorChat/TorChat/TCLogsManager.m | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/TorChat/TorChat/TCConfigurationHelperController.m b/TorChat/TorChat/TCConfigurationHelperController.m index 27dfa39..b24e188 100644 --- a/TorChat/TorChat/TCConfigurationHelperController.m +++ b/TorChat/TorChat/TCConfigurationHelperController.m @@ -24,6 +24,8 @@ #import "TCConfigurationHelperController.h" +#import "TCLogsManager.h" + #import "TCConfigurationCopy.h" #import "TCConfigPlist.h" @@ -128,7 +130,7 @@ + (BOOL)importPrivateKey:(nullable id )configuration if (privateKeyData == nil) { - NSLog(@"Can't read private key data for importation at path '%@' - error:%@", privateKeyPath, error.localizedDescription); + [[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogError message:@"Can't read private key data for importation at path '%@' - error:%@", privateKeyPath, error.localizedDescription]; return NO; } @@ -137,7 +139,7 @@ + (BOOL)importPrivateKey:(nullable id )configuration if (privateKeyString == nil) { - NSLog(@"Can't decode private key data at path '%@'.", privateKeyPath); + [[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogError message:@"Can't decode private key data at path '%@'.", privateKeyPath]; return NO; } @@ -147,7 +149,7 @@ + (BOOL)importPrivateKey:(nullable id )configuration if (match.count == 0 || [match[0] numberOfRanges] < 2) { - NSLog(@"Can't extract RSA private key data at path '%@'.", privateKeyPath); + [[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogError message:@"Can't extract RSA private key data at path '%@'.", privateKeyPath]; return NO; } @@ -162,7 +164,7 @@ + (BOOL)importPrivateKey:(nullable id )configuration // Be sure everything is written to disk before removing original file. if ([configuration synchronize] == NO) { - NSLog(@"Can't synchronize configuration file with imported key."); + [[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogError message:@"Can't synchronize configuration file with imported key."]; return NO; } @@ -170,7 +172,7 @@ + (BOOL)importPrivateKey:(nullable id )configuration TCFileSecureRemove(privateKeyPath); TCFileSecureRemove(hostnamePath); - NSLog(@"Private key imported with success."); + [[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogInfo message:@"Private key imported with success."]; return YES; } diff --git a/TorChat/TorChat/TCLogsManager.m b/TorChat/TorChat/TCLogsManager.m index 3e5e22e..22b48e9 100644 --- a/TorChat/TorChat/TCLogsManager.m +++ b/TorChat/TorChat/TCLogsManager.m @@ -135,6 +135,25 @@ - (void)addLogWithTimestamp:(NSDate *)timestamp key:(NSString *)key kind:(TCLogK { dispatch_sync(_localQueue, ^{ +#if defined(DEBUG) && DEBUG + NSString *kindStr = @"<>"; + + switch (kind) + { + case TCLogError: + kindStr = @""; + break; + case TCLogWarning: + kindStr = @""; + break; + case TCLogInfo: + kindStr = @""; + break; + } + + TCDebugLog(@"~ Log [%@ %@]: %@", key, kindStr, content); +#endif + // Create entry. TCLogEntry *entry = [TCLogEntry logEntryWithTimestamp:timestamp kind:kind message:content];