Skip to content

Commit ada4b7d

Browse files
TheBuggedYRNHeshamMegid
authored andcommitted
[MOB-11936] Add debugLogsLevel to Instabug.init (#337)
A new way to enable SDK debug logs, using the newly added `Instabug.init` API, that works on all platform and for all modules.
1 parent ddb53cb commit ada4b7d

File tree

15 files changed

+102
-39
lines changed

15 files changed

+102
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Bumps Instabug Android SDK to v11.8.0
44
* Bumps Instabug iOS SDK to v11.7.0
55
* Deprecates `Instabug.start` in favour of the new `Instabug.init` API.
6+
* Deprecates `Instabug.setDebugEnabled`, `Instabug.setSdkDebugLogsLevel`, and `APM.setLogLevel` in favour of `debugLogsLevel` property, which can be passed while initializing the SDK using `Instabug.init`.
7+
* Deprecates the `IBGSDKDebugLogsLevel` enum in favour of the `LogLevel` enum.
8+
* Deprecates both `warning` and `info` values from the `LogLevel` enum.
69
* Adds `hungarian` and `finnish` locales support
710
* Adds missing mapping for `norwegian` and `slovak` locales on iOS
811
* Exports native Android SDK

android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public void setEnabled(@NonNull Boolean isEnabled) {
8484
}
8585
}
8686

87-
public void init(@NonNull String token, @NonNull List<String> invocationEvents) {
87+
@Override
88+
public void init(@NonNull String token, @NonNull List<String> invocationEvents, @NonNull String debugLogsLevel) {
8889
setCurrentPlatform();
8990

9091
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
@@ -94,9 +95,13 @@ public void init(@NonNull String token, @NonNull List<String> invocationEvents)
9495
}
9596

9697
final Application application = (Application) context;
98+
final int parsedLogLevel = ArgsRegistry.sdkLogLevels.get(debugLogsLevel);
99+
97100
new Instabug.Builder(application, token)
98101
.setInvocationEvents(invocationEventsArray)
102+
.setSdkDebugLogsLevel(parsedLogLevel)
99103
.build();
104+
100105
Instabug.setScreenshotProvider(screenshotProvider);
101106
}
102107

android/src/main/java/com/instabug/flutter/util/ArgsRegistry.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import androidx.annotation.NonNull;
44

5-
import com.instabug.apm.model.LogLevel;
5+
import com.instabug.library.LogLevel;
66
import com.instabug.bug.BugReporting;
77
import com.instabug.bug.invocation.Option;
88
import com.instabug.featuresrequest.ActionType;
@@ -30,15 +30,26 @@ public T get(Object key) {
3030
}
3131
}
3232

33-
public static final ArgsMap<Integer> logLevels = new ArgsMap<Integer>() {{
33+
public static final ArgsMap<Integer> sdkLogLevels = new ArgsMap<Integer>() {{
3434
put("LogLevel.none", LogLevel.NONE);
3535
put("LogLevel.error", LogLevel.ERROR);
36-
put("LogLevel.warning", LogLevel.WARNING);
37-
put("LogLevel.info", LogLevel.INFO);
36+
put("LogLevel.warning", LogLevel.ERROR); // Deprecated
37+
put("LogLevel.info", LogLevel.DEBUG); // Deprecated
3838
put("LogLevel.debug", LogLevel.DEBUG);
3939
put("LogLevel.verbose", LogLevel.VERBOSE);
4040
}};
4141

42+
@SuppressWarnings("DeprecatedIsStillUsed")
43+
@Deprecated()
44+
public static final ArgsMap<Integer> logLevels = new ArgsMap<Integer>() {{
45+
put("LogLevel.none", com.instabug.apm.model.LogLevel.NONE);
46+
put("LogLevel.error", com.instabug.apm.model.LogLevel.ERROR);
47+
put("LogLevel.warning", com.instabug.apm.model.LogLevel.WARNING);
48+
put("LogLevel.info", com.instabug.apm.model.LogLevel.INFO);
49+
put("LogLevel.debug", com.instabug.apm.model.LogLevel.DEBUG);
50+
put("LogLevel.verbose", com.instabug.apm.model.LogLevel.VERBOSE);
51+
}};
52+
4253
public static ArgsMap<InstabugInvocationEvent> invocationEvents = new ArgsMap<InstabugInvocationEvent>() {{
4354
put("InvocationEvent.none", InstabugInvocationEvent.NONE);
4455
put("InvocationEvent.shake", InstabugInvocationEvent.SHAKE);

android/src/test/java/com/instabug/flutter/ArgsRegistryTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.junit.Assert.assertTrue;
44

5-
import com.instabug.apm.model.LogLevel;
5+
import com.instabug.library.LogLevel;
66
import com.instabug.bug.BugReporting;
77
import com.instabug.bug.invocation.Option;
88
import com.instabug.featuresrequest.ActionType;
@@ -21,18 +21,31 @@
2121
import org.junit.Test;
2222

2323
public class ArgsRegistryTest {
24-
2524
@Test
26-
public void testLogLevels() {
25+
public void testSdkLogLevels() {
2726
Integer[] values = {
2827
LogLevel.NONE,
2928
LogLevel.ERROR,
30-
LogLevel.WARNING,
31-
LogLevel.INFO,
3229
LogLevel.DEBUG,
3330
LogLevel.VERBOSE,
3431
};
3532

33+
for (Integer value : values) {
34+
assertTrue(ArgsRegistry.sdkLogLevels.containsValue(value));
35+
}
36+
}
37+
38+
@Test
39+
public void testLogLevels() {
40+
Integer[] values = {
41+
com.instabug.apm.model.LogLevel.NONE,
42+
com.instabug.apm.model.LogLevel.ERROR,
43+
com.instabug.apm.model.LogLevel.WARNING,
44+
com.instabug.apm.model.LogLevel.INFO,
45+
com.instabug.apm.model.LogLevel.DEBUG,
46+
com.instabug.apm.model.LogLevel.VERBOSE,
47+
};
48+
3649
for (Integer value : values) {
3750
assertTrue(ArgsRegistry.logLevels.containsValue(value));
3851
}

android/src/test/java/com/instabug/flutter/InstabugApiTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.instabug.library.Instabug;
3131
import com.instabug.library.InstabugColorTheme;
3232
import com.instabug.library.InstabugCustomTextPlaceHolder;
33+
import com.instabug.library.LogLevel;
3334
import com.instabug.library.Platform;
3435
import com.instabug.library.invocation.InstabugInvocationEvent;
3536
import com.instabug.library.model.NetworkLog;
@@ -100,18 +101,20 @@ public void testSetCurrentPlatform() {
100101
}
101102

102103
@Test
103-
public void testStart() {
104+
public void testSdkInit() {
104105
String token = "app-token";
105106
List<String> invocationEvents = Collections.singletonList("InvocationEvent.floatingButton");
107+
String logLevel = "LogLevel.error";
106108

107109
MockedConstruction<Instabug.Builder> mInstabugBuilder = mockConstruction(Instabug.Builder.class, (mock, context) -> {
108110
String actualToken = (String) context.arguments().get(1);
109111
// Initializes Instabug with the correct token
110112
assertEquals(token, actualToken);
111113
when(mock.setInvocationEvents(any())).thenReturn(mock);
114+
when(mock.setSdkDebugLogsLevel(anyInt())).thenReturn(mock);
112115
});
113116

114-
api.init(token, invocationEvents);
117+
api.init(token, invocationEvents, logLevel);
115118

116119
Instabug.Builder builder = mInstabugBuilder.constructed().get(0);
117120

@@ -122,6 +125,7 @@ public void testStart() {
122125
mInstabugBuilder.constructed().size()
123126
);
124127
verify(builder).setInvocationEvents(InstabugInvocationEvent.FLOATING_BUTTON);
128+
verify(builder).setSdkDebugLogsLevel(LogLevel.ERROR);
125129
verify(builder).build();
126130

127131
// Sets screenshot provider

example/ios/InstabugSampleTests/InstabugApiTests.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ - (void)testSetEnabled {
3434
OCMVerify([self.mInstabug setEnabled:YES]);
3535
}
3636

37-
- (void)testStart {
37+
- (void)testInit {
3838
NSString *token = @"app-token";
3939
NSArray<NSString *> *invocationEvents = @[@"InvocationEvent.floatingButton", @"InvocationEvent.screenshot"];
40+
NSString *logLevel = @"LogLevel.error";
4041
FlutterError *error;
4142

42-
[self.api initToken:token invocationEvents:invocationEvents error:&error];
43+
[self.api initToken:token invocationEvents:invocationEvents debugLogsLevel:logLevel error:&error];
4344

4445
OCMVerify([self.mInstabug setCurrentPlatform:IBGPlatformFlutter]);
45-
46+
OCMVerify([self.mInstabug setSdkDebugLogsLevel:IBGSDKDebugLogsLevelError]);
4647
OCMVerify([self.mInstabug startWithToken:token invocationEvents:(IBGInvocationEventFloatingButton | IBGInvocationEventScreenshot)]);
4748
}
4849

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void main() {
99
Instabug.init(
1010
token: 'ed6f659591566da19b67857e1b9d40ab',
1111
invocationEvents: [InvocationEvent.floatingButton],
12+
debugLogsLevel: LogLevel.verbose,
1213
);
1314

1415
Instabug.setWelcomeMessageMode(WelcomeMessageMode.disabled);

ios/Classes/Modules/InstabugApi.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ - (void)setEnabledIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nullable
1818
Instabug.enabled = [isEnabled boolValue];
1919
}
2020

21-
- (void)initToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invocationEvents error:(FlutterError *_Nullable *_Nonnull)error {
21+
- (void)initToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invocationEvents debugLogsLevel:(NSString *)debugLogsLevel error:(FlutterError *_Nullable *_Nonnull)error {
2222
SEL setPrivateApiSEL = NSSelectorFromString(@"setCurrentPlatform:");
2323
if ([[Instabug class] respondsToSelector:setPrivateApiSEL]) {
2424
NSInteger *platformID = IBGPlatformFlutter;
@@ -35,6 +35,9 @@ - (void)initToken:(NSString *)token invocationEvents:(NSArray<NSString *> *)invo
3535
resolvedEvents |= (ArgsRegistry.invocationEvents[event]).integerValue;
3636
}
3737

38+
IBGSDKDebugLogsLevel resolvedLogLevel = (ArgsRegistry.sdkLogLevels[debugLogsLevel]).integerValue;
39+
40+
[Instabug setSdkDebugLogsLevel:resolvedLogLevel];
3841
[Instabug startWithToken:token invocationEvents:resolvedEvents];
3942
}
4043

ios/Classes/Util/ArgsRegistry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ typedef NSDictionary<NSString *, NSNumber *> ArgsDictionary;
66
@interface ArgsRegistry : NSObject
77

88
+ (ArgsDictionary *)sdkLogLevels;
9-
+ (ArgsDictionary *)logLevels;
9+
+ (ArgsDictionary *)logLevels __deprecated_msg("Use sdkLogLevels instead.");
1010
+ (ArgsDictionary *)invocationEvents;
1111
+ (ArgsDictionary *)invocationOptions;
1212
+ (ArgsDictionary *)colorThemes;

ios/Classes/Util/ArgsRegistry.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ @implementation ArgsRegistry
44

55
+ (ArgsDictionary *)sdkLogLevels {
66
return @{
7-
@"IBGSDKDebugLogsLevel.verbose" : @(IBGSDKDebugLogsLevelVerbose),
8-
@"IBGSDKDebugLogsLevel.debug" : @(IBGSDKDebugLogsLevelDebug),
9-
@"IBGSDKDebugLogsLevel.error" : @(IBGSDKDebugLogsLevelError),
10-
@"IBGSDKDebugLogsLevel.none" : @(IBGSDKDebugLogsLevelNone),
7+
@"LogLevel.none" : @(IBGLogLevelNone),
8+
@"LogLevel.error" : @(IBGSDKDebugLogsLevelError),
9+
@"LogLevel.warning" : @(IBGSDKDebugLogsLevelError), // Deprecated
10+
@"LogLevel.info" : @(IBGSDKDebugLogsLevelDebug), // Deprecated
11+
@"LogLevel.debug" : @(IBGSDKDebugLogsLevelDebug),
12+
@"LogLevel.verbose" : @(IBGSDKDebugLogsLevelVerbose),
13+
14+
@"IBGSDKDebugLogsLevel.verbose" : @(IBGSDKDebugLogsLevelVerbose), // Deprecated
15+
@"IBGSDKDebugLogsLevel.debug" : @(IBGSDKDebugLogsLevelDebug), // Deprecated
16+
@"IBGSDKDebugLogsLevel.error" : @(IBGSDKDebugLogsLevelError), // Deprecated
17+
@"IBGSDKDebugLogsLevel.none" : @(IBGSDKDebugLogsLevelNone), // Deprecated
1118
};
1219
}
1320

@@ -214,4 +221,4 @@ + (ArgsDictionary *)locales {
214221
};
215222
}
216223

217-
@end
224+
@end

0 commit comments

Comments
 (0)