Skip to content

Commit

Permalink
Limit number of lines in TLOFileLogger.
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Aug 5, 2012
1 parent 410ffa5 commit 6e71f93
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
5 changes: 2 additions & 3 deletions Classes/Headers/NSDictionaryHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@

- (NSString *)keyIgnoringCase:(NSString *)baseKey;

- (NSDictionary *)sortedDictionary;
- (NSArray *)sortedDictionaryKeys;
- (id)sortedDictionary;
@end

@interface NSMutableDictionary (TXMutableDictionaryHelper)
Expand All @@ -66,6 +67,4 @@
- (void)setLongLong:(long long)value forKey:(NSString *)key;
- (void)setDouble:(TXNSDouble)value forKey:(NSString *)key;
- (void)setPointer:(void *)value forKey:(NSString *)key;

- (NSMutableDictionary *)sortedDictionary;
@end
5 changes: 3 additions & 2 deletions Classes/Headers/TLOFileLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
@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, assign) NSInteger maxEntryCount; // Only used if (writePlainText == NO)
@property (nonatomic, strong) NSString *filename;
@property (nonatomic, strong) NSString *fileWritePath;
@property (nonatomic, strong) NSFileHandle *file;
Expand All @@ -66,8 +67,8 @@
- (void)reset;
- (void)reopenIfNeeded;

- (id)data; // Types: (NSData if writePlainText == YES),
// (NSDictionary if writePlainText == NO)
- (id)data; // Types: (NSData writePlainText == YES),
// (NSDictionary writePlainText == NO)
// or nil

- (NSString *)buildPath;
Expand Down
22 changes: 7 additions & 15 deletions Classes/Helpers/Cocoa (Objective-C)/NSDictionaryHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,14 @@ - (NSString *)keyIgnoringCase:(NSString *)baseKey
return nil;
}

- (NSDictionary *)sortedDictionary
- (NSArray *)sortedDictionaryKeys
{
NSArray *sortedKeys = [self.allKeys sortedArrayUsingSelector:@selector(compare:)];
return [self.allKeys sortedArrayUsingSelector:@selector(compare:)];
}

- (id)sortedDictionary
{
NSArray *sortedKeys = [self sortedDictionaryKeys];

NSMutableDictionary *newDict = [NSMutableDictionary dictionary];

Expand Down Expand Up @@ -229,17 +234,4 @@ - (void)setPointer:(void *)value forKey:(NSString *)key
self[key] = [NSValue valueWithPointer:value];
}

- (NSMutableDictionary *)sortedDictionary
{
NSArray *sortedKeys = [self.allKeys sortedArrayUsingSelector:@selector(compare:)];

NSMutableDictionary *newDict = [NSMutableDictionary dictionary];

for (NSString *key in sortedKeys) {
newDict[key] = self[key];
}

return newDict;
}

@end
34 changes: 33 additions & 1 deletion Classes/Library/TLOFileLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,42 @@ - (id)data
} else {
NSMutableDictionary *propertyList = self.propertyList.mutableCopy;

// ---- //

if (NSObjectIsNotEmpty(_temporaryPropertyListItems)) {
[propertyList addEntriesFromDictionary:_temporaryPropertyListItems];
}


// ---- //

if (self.maxEntryCount >= 1) {
if (propertyList.count >= self.maxEntryCount) {
NSArray *reverKkeys = propertyList.sortedDictionaryKeys.reverseObjectEnumerator.allObjects;

NSMutableDictionary *newDict = [NSMutableDictionary dictionary];

NSInteger loopCount = 0;

// ---- //

for (NSString *key in reverKkeys) {
if (loopCount >= self.maxEntryCount) {
break;
}

[newDict setObject:[propertyList objectForKey:key] forKey:key];

loopCount += 1;
}

// ---- //

return [newDict sortedDictionary];
}
}

// ---- //

return [propertyList sortedDictionary];
}

Expand Down
3 changes: 3 additions & 0 deletions Classes/Views/Channel View/TVCLogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ - (void)setMaxLines:(NSInteger)value
[self savePosition];
[self setNeedsLimitNumberOfLines];
}

self.logFile.maxEntryCount = [TPCPreferences maxLogLines];
}

#pragma mark -
Expand Down Expand Up @@ -109,6 +111,7 @@ - (void)setUp
self.logFile.hashFilename = YES;
self.logFile.writePlainText = NO;
self.logFile.fileWritePath = [TPCPreferences whereTemporaryPath];
self.logFile.maxEntryCount = [TPCPreferences maxLogLines];

self.view = [[TVCLogView alloc] initWithFrame:NSZeroRect];

Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
<string>12263</string>
<string>12269</string>
<key>TXBundleBuildReference</key>
<string>2.1.1-274-g363c972-appstore</string>
<string>2.1.1-275-g410ffa5-debug</string>
</dict>
</plist>

0 comments on commit 6e71f93

Please sign in to comment.