Skip to content

Commit

Permalink
Removing weak reference to key when logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
drekka committed Oct 12, 2016
1 parent 7906918 commit eb9cfbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion StoryTeller/STStoryTeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
@param messageTemplate a standard NSString format message.
@param ... a list of values for the message template.
*/
-(void) record:(__weak id) key
-(void) record:(id) key
file:(const char *) fileName
method:(const char *) methodName
lineNumber:(int) lineNumber
Expand Down
24 changes: 11 additions & 13 deletions StoryTeller/STStoryTeller.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ -(instancetype) init {

#pragma mark - Activating logging

-(void) startLogging:(NSString * _Nonnull) keyExpression {
-(void) startLogging:(NSString *) keyExpression {
NSLog(@"Story Teller: Activating log: %@", keyExpression);
id<STMatcher> matcher = [_expressionMatcherFactory parseExpression:keyExpression];

Expand All @@ -86,33 +86,31 @@ -(int) numberActiveScopes {
return (int)[_activeKeys count];
}

-(id) startScope:(__weak id _Nonnull) key {
-(id) startScope:(__weak id) key {
[_activeKeys addObject:key];
return [[STDeallocHook alloc] initWithBlock:^{
[[STStoryTeller storyTeller] endScope:key];
}];
}

-(void) endScope:(__weak id _Nonnull) key {
-(void) endScope:(__weak id) key {
[_activeKeys removeObject:key];
}

-(BOOL) isScopeActive:(__weak id _Nonnull) key {
-(BOOL) isScopeActive:(__weak id) key {
return [_activeKeys containsObject:key];
}

#pragma mark - Logging

-(void) record:(__weak id _Nonnull) key
file:(const char * _Nonnull) fileName
method:(const char * _Nonnull) methodName
-(void) record:(id) key
file:(const char *) fileName
method:(const char *) methodName
lineNumber:(int) lineNumber
message:(NSString * _Nonnull) messageTemplate, ... {

id strongKey = key;
message:(NSString *) messageTemplate, ... {

// Only continue if the key is being logged.
if (![self shouldLogKey:strongKey]) {
if (![self shouldLogKey:key]) {
return;
}

Expand All @@ -127,10 +125,10 @@ -(void) record:(__weak id _Nonnull) key
fromFile:fileName
fromMethod:methodName
lineNumber:lineNumber
key:strongKey];
key:key];
}

-(void) execute:(__weak id _Nonnull) key block:(void (^ _Nonnull)(id _Nonnull)) block {
-(void) execute:(__weak id) key block:(void (^)(id)) block {
id strongKey = key;
if ([self shouldLogKey:strongKey]) {
block(strongKey);
Expand Down

0 comments on commit eb9cfbe

Please sign in to comment.