Tooling: Send app device logs to Testfairy properly

React Native uses 'asl' to do logging, not NSLog, so we have to hook into that
to get logs sent to Testfairy. This means we get all the app device logs you
normally get in development, not just whatever happens in JS land.

- Modified default logging function when flag is set
- Delete Prefix header file and NSLog Macro
This commit is contained in:
Oskar Thorén 2017-09-09 17:14:40 +02:00 committed by Roman Volosovskyi
parent 3e1d731111
commit ed3597fd7c
3 changed files with 44 additions and 19 deletions

View File

@ -1,13 +0,0 @@
// PrefixHeader.pch
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
#endif /* PrefixHeader_pch */
#import "TestFairy.h"
#define NSLog(s, ...) do { NSLog(s, ##__VA_ARGS__); TFLog(s, ##__VA_ARGS__); } while (0)

View File

@ -1987,8 +1987,8 @@
"$(PROJECT_DIR)/Pods/**", "$(PROJECT_DIR)/Pods/**",
"$(PROJECT_DIR)", "$(PROJECT_DIR)",
); );
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "Status-Prefix.pch"; GCC_PREFIX_HEADER = "";
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
@ -2046,8 +2046,8 @@
"$(PROJECT_DIR)/Pods/**", "$(PROJECT_DIR)/Pods/**",
"$(PROJECT_DIR)", "$(PROJECT_DIR)",
); );
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = NO;
GCC_PREFIX_HEADER = "Status-Prefix.pch"; GCC_PREFIX_HEADER = "";
HEADER_SEARCH_PATHS = ( HEADER_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,

View File

@ -9,6 +9,7 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import <asl.h>
#import "ReactNativeConfig.h" #import "ReactNativeConfig.h"
#import "React/RCTLog.h" #import "React/RCTLog.h"
#import "RCTBundleURLProvider.h" #import "RCTBundleURLProvider.h"
@ -17,12 +18,48 @@
#import "TestFairy.h" #import "TestFairy.h"
#import "RNFIRMessaging.h" #import "RNFIRMessaging.h"
/* Macro to send app logs to TestFairy, potential duplicate of prefix header */
#define NSLog(s, ...) do { NSLog(s, ##__VA_ARGS__); TFLog(s, ##__VA_ARGS__); } while (0)
@import Instabug; @import Instabug;
@implementation AppDelegate @implementation AppDelegate
/* Modified version of RCTDefaultLogFunction that also directs all app logs to TestFairy. */
RCTLogFunction RCTTestFairyLogFunction = ^(
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);
/* Only custom part */
TFLog(log);
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);
};
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
@ -32,6 +69,7 @@
NSString *debugLogsEnabled = [ReactNativeConfig envFor:@"DEBUG_LOGS_ENABLED"]; NSString *debugLogsEnabled = [ReactNativeConfig envFor:@"DEBUG_LOGS_ENABLED"];
if([debugLogsEnabled isEqualToString:@"1"]){ if([debugLogsEnabled isEqualToString:@"1"]){
RCTSetLogThreshold(RCTLogLevelInfo - 1); RCTSetLogThreshold(RCTLogLevelInfo - 1);
RCTSetLogFunction(RCTTestFairyLogFunction);
} }
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];