'RCTLog.h' file not found
This is a configuration problem of the project. Please refer to my ReactNative project construction and transformation. Today, I will talk about the problem of crazy log output of RN during xcode debugging.
Default log configuration: default level RCTDefaultLogThreshold, default printing function RCTDefaultLogThreshold:
The level of logging
- Debug: Logs of the higher level are traced by default
- When release, the default log level is error or higher
Therefore, you can change the log input level, as follows can reduce the log input during Debug, at the same time can see the log during release, the APP online to turn off the log!!
/ / the AppDelegate. M#import <React/RCTLog.h>
#ifdef DEBUG
RCTSetLogThreshold(RCTLogLevelInfo);
#else
RCTSetLogThreshold(RCTLogLevelTrace);
#endif
Copy the code
Source of a log
There are two log functions, _RCTLogNativeInternal and _RCTLogJavaScriptInternal, but they are private
The log function
RCTSetLogThreshold \ RCTGetLogThreshold is the log level:
RCTLogLevel RCTGetLogThreshold()
{
return RCTCurrentLogThreshold;
}
void RCTSetLogFunction(RCTLogFunction logFunction)
{
RCTCurrentLogFunction = logFunction;
}
Copy the code
RCTSetLogFunction \ RCTGetLogFunction is used to change the default log printing function, that is, to customize the printing function, RCTAddLogFunction is added to the default log output mode.
/**
* A block signature to be used for custom logging functions. In most cases you
* will want to pass these arguments to the RCTFormatLog function in order to
* generate a string.
*/
typedef void (^RCTLogFunction)(
RCTLogLevel level,
RCTLogSource source,
NSString *fileName,
NSNumber *lineNumber,
NSString *message
);
Copy the code
RCTLogFunction RCTGetLogFunction()
{
if(! RCTCurrentLogFunction) { RCTCurrentLogFunction = RCTDefaultLogFunction; }return RCTCurrentLogFunction;
}
void RCTAddLogFunction(RCTLogFunction logFunction)
{
RCTLogFunction existing = RCTGetLogFunction();
if (existing) {
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
existing(level, source, fileName, lineNumber, message);
logFunction(level, source, fileName, lineNumber, message);
});
} else {
RCTSetLogFunction(logFunction);
}
}
/**
* returns the topmost stacked log function for the current thread, which
* may not be the same as the current value of RCTCurrentLogFunction.
*/
static RCTLogFunction RCTGetLocalLogFunction()
{
NSMutableDictionary *threadDictionary = [NSThread currentThread].threadDictionary;
NSArray<RCTLogFunction> *functionStack = threadDictionary[RCTLogFunctionStack];
RCTLogFunction logFunction = functionStack.lastObject;
if (logFunction) {
return logFunction;
}
return RCTGetLogFunction();
}
Copy the code
The following is the default print function
RCTLogFunction RCTDefaultLogFunction = ^(
RCTLogLevel level,
__unused RCTLogSource source,
NSString *fileName,
NSNumber *lineNumber,
NSString *message
)
{
NSString *log = RCTFormatLog([NSDate date], level, fileName, lineNumber, message);
fprintf(stderr, "%s\n", log.UTF8String);
fflush(stderr);
int aslLevel;
switch(level) {
case RCTLogLevelTrace:
aslLevel = ASL_LEVEL_DEBUG;
break;
case RCTLogLevelInfo:
aslLevel = ASL_LEVEL_NOTICE;
break;
case RCTLogLevelWarning:
aslLevel = ASL_LEVEL_WARNING;
break;
case RCTLogLevelError:
aslLevel = ASL_LEVEL_ERR;
break;
case RCTLogLevelFatal:
aslLevel = ASL_LEVEL_CRIT;
break;
}
asl_log(NULL, NULL, aslLevel, "%s", message.UTF8String);
};
Copy the code