Skip to content

Commit

Permalink
Merge pull request #1108 from react-native-mapbox-gl/mattijsf/logger-fix
Browse files Browse the repository at this point in the history
Prevent emitting log events without listeners
  • Loading branch information
mattijsf authored Nov 17, 2020
2 parents 8863207 + e21ebe8 commit d6c8a93
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ios/RCTMGL/RCTMGLLogging.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

@import Mapbox;

@interface RCTMGLLogging()
@property (nonatomic) BOOL hasListeners;
@end

@implementation RCTMGLLogging

+ (id)allocWithZone:(NSZone *)zone {
Expand Down Expand Up @@ -37,8 +41,22 @@ + (BOOL)requiresMainQueueSetup
return @[@"LogEvent"];
}

- (void)startObserving
{
[super startObserving];
self.hasListeners = true;
}

- (void)stopObserving
{
[super stopObserving];
self.hasListeners = false;
}

- (void)sendLogWithLevel:(MGLLoggingLevel)loggingLevel filePath:(NSString*)filePath line:(NSUInteger)line message:(NSString*)message
{
if (!self.hasListeners) return;

NSString* level = @"n/a";
switch (loggingLevel) {
case MGLLoggingLevelInfo:
Expand Down

0 comments on commit d6c8a93

Please sign in to comment.