Skip to content

Commit

Permalink
- Enhance logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
javerous committed Aug 14, 2016
1 parent d7cd6bd commit 2c6a672
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 7 additions & 5 deletions TorChat/TorChat/TCConfigurationHelperController.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#import "TCConfigurationHelperController.h"

#import "TCLogsManager.h"

#import "TCConfigurationCopy.h"

#import "TCConfigPlist.h"
Expand Down Expand Up @@ -128,7 +130,7 @@ + (BOOL)importPrivateKey:(nullable id <TCConfigAppEncryptable>)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;
}

Expand All @@ -137,7 +139,7 @@ + (BOOL)importPrivateKey:(nullable id <TCConfigAppEncryptable>)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;
}

Expand All @@ -147,7 +149,7 @@ + (BOOL)importPrivateKey:(nullable id <TCConfigAppEncryptable>)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;
}

Expand All @@ -162,15 +164,15 @@ + (BOOL)importPrivateKey:(nullable id <TCConfigAppEncryptable>)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;
}

// Remove previous file on disk.
TCFileSecureRemove(privateKeyPath);
TCFileSecureRemove(hostnamePath);

NSLog(@"Private key imported with success.");
[[TCLogsManager sharedManager] addGlobalLogWithKind:TCLogInfo message:@"Private key imported with success."];

return YES;
}
Expand Down
19 changes: 19 additions & 0 deletions TorChat/TorChat/TCLogsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @"<error>";
break;
case TCLogWarning:
kindStr = @"<warning>";
break;
case TCLogInfo:
kindStr = @"<info>";
break;
}

TCDebugLog(@"~ Log [%@ %@]: %@", key, kindStr, content);
#endif

// Create entry.
TCLogEntry *entry = [TCLogEntry logEntryWithTimestamp:timestamp kind:kind message:content];

Expand Down

0 comments on commit 2c6a672

Please sign in to comment.