Skip to content

Commit

Permalink
Added logException
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysharm committed May 13, 2020
1 parent 1194be3 commit 84a3ff1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Plugins/TestFairy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class TestFairy : MonoBehaviour
[DllImport("__Internal")]
private static extern void TestFairy_log(string name);

[DllImport("__Internal")]
private static extern void TestFairy_logException(string name, string trace);

[DllImport("__Internal")]
private static extern void TestFairy_hideWebViewElements(string cssSelector);

Expand Down Expand Up @@ -337,6 +340,18 @@ public static void log(string message) {
#endif
}

public static void logException(string message, string stacktrace) {
#if UNITY_IPHONE && !UNITY_EDITOR
TestFairy_logException(message, stacktrace);
#elif UNITY_ANDROID && !UNITY_EDITOR
using(AndroidJavaClass pluginClass = getTestFairyClass()) {
if(pluginClass != null) {
pluginClass.CallStatic("logThrowable", "TestFairyUnity", stacktrace);
}
}
#endif
}

public static void hideWebViewElements(string cssSelector) {
#if UNITY_IPHONE && !UNITY_EDITOR
TestFairy_hideWebViewElements(cssSelector);
Expand Down
8 changes: 8 additions & 0 deletions Plugins/iOS/TestFairyUnityWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ void TestFairy_log(char *message) {
TFLog(@"%@", value);
}

void TestFairy_logException(char *message, char *trace) {
NSString *messageString = message == NULL ? @"" : [NSString stringWithUTF8String:message];
NSString *traceString = trace == NULL ? @"" : [NSString stringWithUTF8String:trace];

NSError *error = [NSError errorWithDomain:@"com.testfairy.unity" code:-1 userInfo:@{NSLocalizedDescriptionKey: messageString}];
[TestFairy logError:error stacktrace:[traceString componentsSeparatedByString:@"\n"]];
}

void TestFairy_hideWebViewElements(char *cssSelector) {
if (cssSelector == NULL) {
return;
Expand Down

0 comments on commit 84a3ff1

Please sign in to comment.