Remote Logging
Beta release
Sauce Labs Mobile App Distribution allows developers to log items with a session without logging into the console output. In some cases, workarounds allow you to wrap the Sauce Labs Mobile App Distribution remote logging method in a way that both log to the console and the session.
- Android
- iOS Objective C
- iOS Swift
- React Native
TestFairy.log("<tag>", "<message>");
// Be sure to import the SDK
import com.testfairy.TestFairy;
TestFairy.log("Tag", "Hello, Sauce Labs Mobile App Distribution!");
TFLog(@"<message with format>", <arguments>);
[TestFairy log:@"<message>"];
// Be sure to import the SDK
#import "TestFairy.h"
TFLog(@"Hello, %@", @"Sauce Labs Mobile App Distribution!");
[TestFairy log:@"Hello, Sauce Labs Mobile App Distribution!"];
NSLog to the SDK so you can continue to use NSLog and see all your log statements in your session.To enable this, 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 Sauce Labs Mobile App Distribution).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 the compiler settings group, 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 Headeris set to YES. - Clean your project, and rebuild.
TestFairy.log("<message>")
// Be sure to import the SDK
import TestFairy
TestFairy.log("Hello, Sauce Labs Mobile App Distribution!")
print or NSLog output as well, call TestFairy.log from your logging helper. The Objective-C NSLog macro approach in the Objective C tab does not apply to Swift print.TestFairy.log("<message>");
// Be sure to import the SDK
import TestFairy from '@saucelabs/mobile-beta-react-native';
TestFairy.log("Hello, Sauce Labs Mobile App Distribution!");
log are serialized to JSON before they are sent.