Skip to content

Commit

Permalink
Base for new TLOFileLogger.
Browse files Browse the repository at this point in the history
Designed to support plain text logging as well as logging into
a property list. Plain text logging is what Textual has always
used. The property list support is designed to be used for
internal purposes to reload messages. Untested.
  • Loading branch information
emsquared committed Aug 2, 2012
1 parent 3898858 commit 1f6ac95
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Classes/Dialogs/Preferences/TDCPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ - (void)onTranscriptFolderChanged:(id)sender
relativeToURL:nil
error:&error];
if (error) {
NSLog(@"Error creating bookmark for URL (%@): %@", pathURL, error);
LogToConsole(@"Error creating bookmark for URL (%@): %@", pathURL, error);
} else {
[TPCPreferences setTranscriptFolder:bookmark];
}
Expand Down
1 change: 0 additions & 1 deletion Classes/Headers/IRCChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ typedef enum IRCChannelStatus : NSInteger {
@property (nonatomic, weak) NSString *channelTypeString;
@property (nonatomic, strong) NSString *topic;
@property (nonatomic, strong) NSString *storedTopic;
@property (nonatomic, strong) NSString *logDate;
@property (nonatomic, assign) BOOL isOp;
@property (nonatomic, assign) BOOL isHalfOp;
@property (nonatomic, assign) BOOL isModeInit;
Expand Down
1 change: 0 additions & 1 deletion Classes/Headers/IRCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ typedef enum IRCDisconnectType : NSInteger {
@property (nonatomic, assign) BOOL isIdentifiedWithSASL;
@property (nonatomic, strong) TLOFileLogger *logFile;
@property (nonatomic, assign) NSStringEncoding encoding;
@property (nonatomic, strong) NSString *logDate;
@property (nonatomic, strong) NSString *inputNick;
@property (nonatomic, strong) NSString *sentNick;
@property (nonatomic, strong) NSString *myNick;
Expand Down
8 changes: 5 additions & 3 deletions Classes/Headers/StaticDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@
#define TXFoundationBasedUUIDAvailable
#endif

/* http://stackoverflow.com/questions/969130/nslog-tips-and-tricks */
#define LogToConsole(fmt, ...) NSLog([@"%s [Line %d]: " stringByAppendingString:fmt], \
__PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d]: " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define DebugLogToConsole(fmt, ...) LogToConsole(fmt, ##__VA_ARGS__);
#else
#define DLog(...)
#define DebugLogToConsole(...)
#endif

/* Establish Common Pointers */
Expand Down
26 changes: 23 additions & 3 deletions Classes/Headers/TLOFileLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,40 @@
*********************************************************************** */

/*
TLOFileLogger is designed to be used exclusively by Textual (not plugins)
for logging of IRC messages to plain text or property list files. Plain
text logging is used for normal IRC logging while the property list write
option is reserved for internal uses where the exact details of each message
is required for later processing.
The directory in which this class writes to reads the user configured path
unless a different one is specified by a class which implements TLOFileLogger.
*/

#import "TextualApplication.h"

#define TLOFileLoggerConsoleDirectoryName @"Console"
#define TLOFileLoggerChannelDirectoryName @"Channels"
#define TLOFileLoggerPrivateMessageDirectoryName @"Queries"

@interface TLOFileLogger : NSObject
@property (nonatomic, weak) IRCClient *client;
@property (nonatomic, weak) IRCChannel *channel;
@property (nonatomic, assign) BOOL writePlainText; // Plain text or property list.
@property (nonatomic, assign) BOOL hashFilename; // UUID based, flat directory structure.
@property (nonatomic, strong) NSString *filename;
@property (nonatomic, strong) NSString *fileWritePath;
@property (nonatomic, strong) NSFileHandle *file;

- (void)open;
- (void)close;
- (void)reset;
- (void)reopenIfNeeded;

- (void)writeLine:(NSString *)s;

- (NSString *)buildPath;
- (NSString *)buildFileName;

- (void)writePlainTextLine:(NSString *)s;

- (void)writePropertyListEntry:(NSDictionary *)s toKey:(NSString *)key;
@end
2 changes: 1 addition & 1 deletion Classes/Helpers/THOPluginItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void)initWithPluginClass:(Class)primaryClass
NSDictionary *originalEntries = newOutputRulesDict[command];

if ([originalEntries containsKeyIgnoringCase:regex]) {
NSLog(@"Extension Error: Found multiple entries of the same regular expression in an output rule. Using only first. (Command = \"%@\" Expression = \"%@\")", command, regex);
LogToConsole(@"Extension Error: Found multiple entries of the same regular expression in an output rule. Using only first. (Command = \"%@\" Expression = \"%@\")", command, regex);
} else {
newOutputRulesDict[command][regex] = boss_entry;
}
Expand Down
16 changes: 3 additions & 13 deletions Classes/IRC/IRCChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,14 @@ - (BOOL)print:(TVCLogLine *)line withHTML:(BOOL)rawHTML
self.logFile = [TLOFileLogger new];
self.logFile.client = self.client;
self.logFile.channel = self;
}

NSString *comp = [NSString stringWithFormat:@"%@", [NSDate.date dateWithCalendarFormat:@"%Y%m%d%H%M%S" timeZone:nil]];

if (self.logDate) {
if ([self.logDate isEqualToString:comp] == NO) {
self.logDate = comp;

[self.logFile reopenIfNeeded];
}
} else {
self.logDate = comp;
self.logFile.writePlainText = YES;
self.logFile.hashFilename = NO;
}

NSString *logstr = [self.log renderedBodyForTranscriptLog:line];

if (NSObjectIsNotEmpty(logstr)) {
[self.logFile writeLine:logstr];
[self.logFile writePlainTextLine:logstr];
}
}

Expand Down
34 changes: 12 additions & 22 deletions Classes/IRC/IRCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,15 @@ -(void)executeTextualCmdScript:(NSDictionary *)details
NSError *aserror = [NSError new];

NSUserAppleScriptTask *applescript = [[NSUserAppleScriptTask alloc] initWithURL:[NSURL fileURLWithPath:scriptPath] error:&aserror];

if (PointerIsEmpty(applescript)) {
NSLog(TXTLS(@"ScriptExecutionFailure"), [aserror localizedDescription]);
LogToConsole(TXTLS(@"ScriptExecutionFailure"), [aserror localizedDescription]);
} else {
[applescript executeWithAppleEvent:event
completionHandler:^(NSAppleEventDescriptor *result, NSError *error) {

if (PointerIsEmpty(result)) {
NSLog(TXTLS(@"ScriptExecutionFailure"), [error localizedDescription]);
LogToConsole(TXTLS(@"ScriptExecutionFailure"), [error localizedDescription]);
} else {
NSString *finalResult = [result stringValue].trim;

Expand Down Expand Up @@ -1294,7 +1294,7 @@ -(void)executeTextualCmdScript:(NSDictionary *)details
NSAppleEventDescriptor *result = [appleScript executeAppleEvent:event error:&errors];

if (errors && PointerIsEmpty(result)) {
NSLog(TXTLS(@"ScriptExecutionFailure"), errors);
LogToConsole(TXTLS(@"ScriptExecutionFailure"), errors);
} else {
NSString *finalResult = [result stringValue].trim;

Expand All @@ -1303,7 +1303,7 @@ -(void)executeTextualCmdScript:(NSDictionary *)details
}
}
} else {
NSLog(TXTLS(@"ScriptExecutionFailure"), errors);
LogToConsole(TXTLS(@"ScriptExecutionFailure"), errors);
}

} else {
Expand Down Expand Up @@ -2759,7 +2759,7 @@ - (BOOL)sendCommand:(id)str completeTarget:(BOOL)completeTarget target:(NSString
BOOL pluginFound = BOOLValueFromObject([self.world.bundlesForUserInput objectForKey:cmd]);

if (pluginFound && scriptFound) {
NSLog(TXTLS(@"PluginCommandClashErrorMessage") ,cmd);
LogToConsole(TXTLS(@"PluginCommandClashErrorMessage") ,cmd);
} else {
if (pluginFound) {
[self.invokeInBackgroundThread processBundlesUserMessage:
Expand Down Expand Up @@ -2808,7 +2808,7 @@ - (void)sendLine:(NSString *)str
[self.conn sendLine:str];

if (self.rawModeEnabled) {
NSLog(@" << %@", str);
LogToConsole(@" << %@", str);
}

self.world.messagesSent++;
Expand Down Expand Up @@ -3300,24 +3300,14 @@ - (BOOL)printAndLog:(TVCLogLine *)line withHTML:(BOOL)rawHTML
if (PointerIsEmpty(self.logFile)) {
self.logFile = [TLOFileLogger new];
self.logFile.client = self;
}

NSString *comp = [NSString stringWithFormat:@"%@", [NSDate.date dateWithCalendarFormat:@"%Y%m%d%H%M%S" timeZone:nil]];

if (self.logDate) {
if ([self.logDate isEqualToString:comp] == NO) {
self.logDate = comp;

[self.logFile reopenIfNeeded];
}
} else {
self.logDate = comp;
self.logFile.writePlainText = YES;
self.logFile.hashFilename = NO;
}

NSString *logstr = [self.log renderedBodyForTranscriptLog:line];

if (NSObjectIsNotEmpty(logstr)) {
[self.logFile writeLine:logstr];
[self.logFile writePlainTextLine:logstr];
}
}

Expand Down Expand Up @@ -5647,7 +5637,7 @@ - (void)ircConnectionDidReceive:(NSData *)data
s = [NSString stringWithData:data encoding:NSUTF8StringEncoding];

if (PointerIsEmpty(s)) {
NSLog(@"NSData decode failure. (%@)", data);
LogToConsole(@"NSData decode failure. (%@)", data);

return;
}
Expand All @@ -5658,7 +5648,7 @@ - (void)ircConnectionDidReceive:(NSData *)data
self.world.bandwidthIn += [s length];

if (self.rawModeEnabled) {
NSLog(@" >> %@", s);
LogToConsole(@" >> %@", s);
}

if ([TPCPreferences removeAllFormatting]) {
Expand Down
10 changes: 5 additions & 5 deletions Classes/Library/Color Formatting/IRCColorFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ - (NSString *)attributedStringToASCIIFormatting:(NSMutableAttributedString **)st
guessed it was going to be assigned to the substringed value. */
cake = [base.string safeSubstringWithRange:NSMakeRange(effectiveRange.location, totalCalculatedLength)];

DLog(@"cake: %@\nLength: %i", cake, totalCalculatedLength);
DebugLogToConsole(@"cake: %@\nLength: %i", cake, totalCalculatedLength);

/* Truncate at first available space as long as it is within range. */
if (breakLoopAfterAppend && cake.length >= _textTruncationSpacePositionMaxDifferential) {
Expand All @@ -257,14 +257,14 @@ - (NSString *)attributedStringToASCIIFormatting:(NSMutableAttributedString **)st
options:NSBackwardsSearch
range:spaceCharSearchBase];

DLog(@"spaceCharacter: %@", NSStringFromRange(spaceChar));
DebugLogToConsole(@"spaceCharacter: %@", NSStringFromRange(spaceChar));

if (NSDissimilarObjects(spaceChar.location, NSNotFound)) {
totalCalculatedLength = spaceChar.location;

cake = [base.string safeSubstringWithRange:NSMakeRange(effectiveRange.location, totalCalculatedLength)];

DLog(@"newCake: %@\nLength: %i", cake, totalCalculatedLength);
DebugLogToConsole(@"newCake: %@\nLength: %i", cake, totalCalculatedLength);
}
}

Expand Down Expand Up @@ -299,7 +299,7 @@ - (NSString *)attributedStringToASCIIFormatting:(NSMutableAttributedString **)st
effectiveRange.location += totalCalculatedLength;
effectiveRange.length = (base.string.length - stringDeletionLength);

DLog(@"effectiveRange: %@", NSStringFromRange(effectiveRange));
DebugLogToConsole(@"effectiveRange: %@", NSStringFromRange(effectiveRange));

limitRange = effectiveRange;
}
Expand All @@ -309,7 +309,7 @@ - (NSString *)attributedStringToASCIIFormatting:(NSMutableAttributedString **)st

[*string deleteCharactersInRange:NSMakeRange(0, stringDeletionLength)];

DLog(@"string: %@\nresult: %@\nrange: 0, %i", [*string string], result, stringDeletionLength);
DebugLogToConsole(@"string: %@\nresult: %@\nrange: 0, %i", [*string string], result, stringDeletionLength);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ - (void)requestSSLTrustFor:(NSWindow *)docWindow
alternateButton:(NSString *)alternateButton
{
SecTrustRef trust = [self sslCertificateTrustInformation];

DLog(@"SSL Trust Ref: %@", trust);
DebugLogToConsole(@"SSL Trust Ref: %@", trust);

if (PointerIsNotEmpty(trust)) {
SFCertificatePanel *panel = [SFCertificatePanel sharedCertificatePanel];
Expand All @@ -141,7 +141,7 @@ - (SecTrustRef)sslCertificateTrustInformation /* @private */
dispatch_block_t block = ^{
OSStatus status = SSLCopyPeerTrust(self.sslContext, &trust);

DLog(@"SSL Context: %@\nTrust Ref: %@\nCopy Status: %i", self.sslContext, trust, status);
DebugLogToConsole(@"SSL Context: %@\nTrust Ref: %@\nCopy Status: %i", self.sslContext, trust, status);

#pragma unused(status)
};
Expand Down
Loading

0 comments on commit 1f6ac95

Please sign in to comment.