Skip to content

Commit

Permalink
Use getters and setters
Browse files Browse the repository at this point in the history
Summary: As per discussion in #2423 - possible fix for crash. (cc: @​javache)

Please share feedback regarding the PR, we are going to be using this diff in production to see if it fixes the crashes we are seeing.

(fixes #2423)
Closes #2494

Reviewed By: @javache

Differential Revision: D2433515

Pulled By: @nicklockwood
  • Loading branch information
paramaggarwal authored and facebook-github-bot-3 committed Sep 13, 2015
1 parent 9d36fc6 commit b998e5a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions React/Base/RCTLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ - (void)logMessage:(NSString *)message level:(NSString *)level;
static RCTLogFunction RCTCurrentLogFunction;
static RCTLogLevel RCTCurrentLogThreshold;

__attribute__((constructor))
static void RCTLogSetup()
RCTLogLevel RCTGetLogThreshold()
{
RCTCurrentLogFunction = RCTDefaultLogFunction;

if (!RCTCurrentLogThreshold) {
#if RCT_DEBUG
RCTCurrentLogThreshold = RCTLogLevelInfo - 1;
RCTCurrentLogThreshold = RCTLogLevelInfo - 1;
#else
RCTCurrentLogThreshold = RCTLogLevelError;
RCTCurrentLogThreshold = RCTLogLevelError;
#endif

}
return RCTCurrentLogThreshold;
}

RCTLogFunction RCTDefaultLogFunction = ^(
Expand Down Expand Up @@ -88,23 +87,26 @@ void RCTSetLogFunction(RCTLogFunction logFunction)

RCTLogFunction RCTGetLogFunction()
{
if (!RCTCurrentLogFunction) {
RCTCurrentLogFunction = RCTDefaultLogFunction;
}
return RCTCurrentLogFunction;
}

void RCTAddLogFunction(RCTLogFunction logFunction)
{
RCTLogFunction existing = RCTCurrentLogFunction;
RCTLogFunction existing = RCTGetLogFunction();
if (existing) {
RCTCurrentLogFunction = ^(RCTLogLevel level,
NSString *fileName,
NSNumber *lineNumber,
NSString *message) {
RCTSetLogFunction(^(RCTLogLevel level,
NSString *fileName,
NSNumber *lineNumber,
NSString *message) {

existing(level, fileName, lineNumber, message);
logFunction(level, fileName, lineNumber, message);
};
});
} else {
RCTCurrentLogFunction = logFunction;
RCTSetLogFunction(logFunction);
}
}

Expand All @@ -120,7 +122,7 @@ static RCTLogFunction RCTGetLocalLogFunction()
if (logFunction) {
return logFunction;
}
return RCTCurrentLogFunction;
return RCTGetLogFunction();
}

void RCTPerformBlockWithLogFunction(void (^block)(void), RCTLogFunction logFunction)
Expand Down Expand Up @@ -194,7 +196,7 @@ void _RCTLogFormat(
{
RCTLogFunction logFunction = RCTGetLocalLogFunction();
BOOL log = RCT_DEBUG || (logFunction != nil);
if (log && level >= RCTCurrentLogThreshold) {
if (log && level >= RCTGetLogThreshold()) {

// Get message
va_list args;
Expand Down

0 comments on commit b998e5a

Please sign in to comment.