Skip to content

Commit

Permalink
Patching synchronization bug and patch bump.
Browse files Browse the repository at this point in the history
  • Loading branch information
drekka committed Nov 15, 2016
1 parent d0a6f72 commit be81d0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Story Teller is an advanced logging framework that takes an entirely different a

See how it works on the main [Story Teller site](http://drekka.github.io/StoryTeller).

# v1.8.2

* Patching to fix error triggered by multithreaded access to the current logging keys.

# v1.8.1

* Cleaning up some C code around assembling log lines to fix a possible memory leak.
Expand Down
4 changes: 2 additions & 2 deletions StoryTeller.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1.8.1;
CURRENT_PROJECT_VERSION = 1.8.2;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_COMPATIBILITY_VERSION = 1.7;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -860,7 +860,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1.8.1;
CURRENT_PROJECT_VERSION = 1.8.2;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_COMPATIBILITY_VERSION = 1.7;
ENABLE_NS_ASSERTIONS = NO;
Expand Down
42 changes: 26 additions & 16 deletions StoryTeller/STStoryTeller.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,18 @@ -(instancetype) init {
-(void) startLogging:(NSString *) keyExpression {
NSLog(@"Story Teller: Activating log: %@", keyExpression);
id<STMatcher> matcher = [_expressionMatcherFactory parseExpression:keyExpression];

if (_logMatchers.count > 0) {
if (matcher.exclusive) {
@throw [NSException exceptionWithName:@"StoryTellerConfigException" reason:[NSString stringWithFormat:@"%@ cannot be used with other logging expressions", keyExpression] userInfo:nil];
} else if ([_logMatchers anyObject].exclusive) {
@throw [NSException exceptionWithName:@"StoryTellerConfigException" reason:[NSString stringWithFormat:@"Log expression %@ cannot be used with previous exclusive expressions", keyExpression] userInfo:nil];
}
}

[_logMatchers addObject:matcher];

@synchronized (_logMatchers) {
[_logMatchers addObject:matcher];
}
}

#pragma mark - Activating
Expand All @@ -91,14 +93,18 @@ -(int) numberActiveScopes {
}

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

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

-(BOOL) isScopeActive:(__weak id) key {
Expand Down Expand Up @@ -129,12 +135,12 @@ -(void) record:(id) key
lineNumber:(int) lineNumber
message:(NSString *) messageTemplate
args:(va_list) args {

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

// Assemble the main message.
NSString *msg = [[NSString alloc] initWithFormat:messageTemplate arguments:args];

Expand All @@ -153,26 +159,30 @@ -(void) execute:(id) key block:(void (^)()) block {
}

-(BOOL) shouldLogKey:(id) key {

// Check the bypass and active keys.
if ([self isKeyMatched:key]) {
return YES;
}

// If any of the active keys are logging then we also fire.
for (id scopeKey in _activeKeys) {
if ([self isKeyMatched:scopeKey]) {
return YES;
@synchronized (_activeKeys) {
for (id scopeKey in _activeKeys) {
if ([self isKeyMatched:scopeKey]) {
return YES;
}
}
}

return NO;
}

-(BOOL) isKeyMatched:(id) key {
for (id<STMatcher> matcher in _logMatchers) {
if ([matcher storyTeller:self matches:key]) {
return YES;
@synchronized (_logMatchers) {
for (id<STMatcher> matcher in _logMatchers) {
if ([matcher storyTeller:self matches:key]) {
return YES;
}
}
}
return NO;
Expand Down

0 comments on commit be81d0a

Please sign in to comment.