Remote Logging
TestFairy allows developers to log items with a session without logging into the console output. In some cases, workarounds allow you to wrap the TestFairy remote logging method in a way that both log to the console and the session.
- Android
- iOS Objective C
- iOS Swift
- Cordova
- React Native
- Nativescript
- Xamarin
- Unity
- Adobe Air
- Titanium
TestFairy.log("<tag>", "<message>");
// Be sure to import TestFairy
import com.testfairy.TestFairy;
TestFairy.log("Tag", "Hello, TestFairy!");
TFLog(@"<message with format>", <arguments>);
[TestFairy log:@"<message>"];
// Be sure to import TestFairy
#import "TestFairy.h"
TFLog(@"Hello, %@", @"TestFairy!");
[TestFairy log:@"Hello, TestFairy!"];
NSLog
to TestFairy so you can continue to use NSLog
and see all your log statements in your session.To enable sending logs to TestFairy, you have to redefine
NSLog
using a macro with the following lines. This macro allows you to continue using NSLog
in your code while also adding the logs to the matching session in TestFairy).Changing Your Prefix Header
#import "TestFairy.h"
#define NSLog(s, ...) do { NSLog(s, ##__VA_ARGS__); TFLog(s, ##__VA_ARGS__); } while (0)
- Add the above line to a global header in your project, accessible to every class file.
- Update or create a Prefix Header (.pch) for your project. If you do not have a PCH file in your project, you can follow the steps in the next section.
Creating a New Prefix Header
If your project doesn’t already include a Prefix Header (.pch):- Create a new file under iOS > Other > PCH File.
- Name your file
PCH file
. - Add these lines of code to the file:
#import "TestFairy.h"
#define NSLog(s, ...) do { NSLog(s, ##__VA_ARGS__); TFLog(s, ##__VA_ARGS__); } while (0)
- From the Project Navigator, select your project and the corresponding target.
- Project > Build Settings > Search: "Prefix Header".
- Under Apple LLVM 7.0, you get the Prefix Header key.
- Type the file's path, for example:
$(SRCROOT)/$(PROJECT_NAME)/ProjectName-Prefix.pch
. Your file may be at a different location. - Make sure the option
Precompile Prefix Header
is set to YES. - Clean your project, and rebuild.