Skip to content

Commit c1807cb

Browse files
DavidMina96ymabdallah
authored andcommitted
[MOB-11440] Add debugLogsLevel to InstabugConfig (#873)
After adding Instabug.init API that takes an extensible InstabugConfig, this PR does the following: 1. Adds debugLogsLevel optional property to InstabugConfig, and a new enum LogLevel which controls the verbosity of SDK logs. This works on both platforms. 2. Deprecates the old debug logs APIs and enums.
1 parent e4b8c7a commit c1807cb

File tree

13 files changed

+61
-8
lines changed

13 files changed

+61
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Unreleased
22

33
- Deprecates Instabug.start in favour of Instabug.init that takes a configuration object for SDK initialization.
4+
- Deprecates Instabug.setDebugEnabled, Instabug.setSdkDebugLogsLevel, and APM.setLogLevel in favour of debugLogsLevel property, which can be passed to InstabugConfig while initializing the SDK using Instabug.init.
5+
- Deprecates the enums: sdkDebugLogsLevel and logLevel in favour of a new enum LogLevel.
46

57
## 11.6.0 (2022-12-29)
68

android/src/main/java/com/instabug/reactlibrary/ArgsRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static Map<String, Object> getAll() {
5757
putAll(actionTypes);
5858
putAll(extendedBugReportStates);
5959
putAll(reproStates);
60+
putAll(sdkLogLevels);
6061
putAll(promptOptions);
6162
putAll(locales);
6263
putAll(placeholders);
@@ -145,6 +146,13 @@ static Map<String, Object> getAll() {
145146
put("reproStepsDisabled", State.DISABLED);
146147
}};
147148

149+
static final ArgsMap<Integer> sdkLogLevels = new ArgsMap<Integer>() {{
150+
put("sdkDebugLogsLevelNone", com.instabug.library.LogLevel.NONE);
151+
put("sdkDebugLogsLevelError", com.instabug.library.LogLevel.ERROR);
152+
put("sdkDebugLogsLevelDebug", com.instabug.library.LogLevel.DEBUG);
153+
put("sdkDebugLogsLevelVerbose", com.instabug.library.LogLevel.VERBOSE);
154+
}};
155+
148156
@Deprecated
149157
static final ArgsMap<Integer> promptOptions = new ArgsMap<Integer>() {{
150158
put("promptOptionBug", PluginPromptOption.PromptOptionIdentifier.BUG_REPORT);

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.instabug.library.InstabugState;
4040
import com.instabug.library.OnSdkDismissCallback;
4141
import com.instabug.library.Platform;
42+
import com.instabug.library.LogLevel;
4243
import com.instabug.library.extendedbugreport.ExtendedBugReport;
4344
import com.instabug.library.internal.module.InstabugLocale;
4445
import com.instabug.library.invocation.InstabugInvocationEvent;
@@ -133,19 +134,21 @@ public void run() {
133134
* @param invocationEventValues The events that invoke the SDK's UI.
134135
*/
135136
@ReactMethod
136-
public void init(final String token, final ReadableArray invocationEventValues) {
137+
public void init(final String token, final ReadableArray invocationEventValues, final String logLevel) {
137138
MainThreadHandler.runOnMainThread(new Runnable() {
138139
@Override
139140
public void run() {
140141
try {
141142
final ArrayList<String> keys = ArrayUtil.parseReadableArrayOfStrings(invocationEventValues);
142143
final ArrayList<InstabugInvocationEvent> parsedInvocationEvents = ArgsRegistry.invocationEvents.getAll(keys);
144+
final int parsedLogLevel = ArgsRegistry.sdkLogLevels.getOrDefault(logLevel, LogLevel.ERROR);
143145

144146
setCurrentPlatform();
145147
setBaseUrlForDeprecationLogs();
146148

147149
new Instabug.Builder(getCurrentActivity().getApplication(), token)
148150
.setInvocationEvents(parsedInvocationEvents.toArray(new InstabugInvocationEvent[0]))
151+
.setSdkDebugLogsLevel(parsedLogLevel)
149152
.build();
150153

151154
// Temporarily disabling APM hot launches

example/ios/InstabugSampleTests/InstabugSampleTests.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ - (void)testInit {
6666
IBGInvocationEvent floatingButtonInvocationEvent = IBGInvocationEventFloatingButton;
6767
NSString *appToken = @"app_token";
6868
NSArray *invocationEvents = [NSArray arrayWithObjects:[NSNumber numberWithInteger:floatingButtonInvocationEvent], nil];
69+
IBGSDKDebugLogsLevel sdkDebugLogsLevel = IBGSDKDebugLogsLevelDebug;
70+
6971
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing [Instabug init]"];
7072

7173
OCMStub([mock startWithToken:appToken invocationEvents:floatingButtonInvocationEvent]);
72-
[self.instabugBridge init:appToken invocationEvents:invocationEvents];
74+
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel];
7375

7476
[[NSRunLoop mainRunLoop] performBlock:^{
7577
OCMVerify([mock startWithToken:appToken invocationEvents:floatingButtonInvocationEvent]);

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
- (void)setEnabled:(BOOL)isEnabled;
2929

30-
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray;
30+
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel;
3131

3232
- (void)setUserData:(NSString *)userData;
3333

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (dispatch_queue_t)methodQueue {
4141
Instabug.enabled = isEnabled;
4242
}
4343

44-
RCT_EXPORT_METHOD(init:(NSString *)token invocationEvents:(NSArray*)invocationEventsArray) {
44+
RCT_EXPORT_METHOD(init:(NSString *)token invocationEvents:(NSArray*)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel) {
4545
SEL setPrivateApiSEL = NSSelectorFromString(@"setCurrentPlatform:");
4646
if ([[Instabug class] respondsToSelector:setPrivateApiSEL]) {
4747
NSInteger *platform = IBGPlatformReactNative;
@@ -57,7 +57,8 @@ - (dispatch_queue_t)methodQueue {
5757
invocationEvents |= [boxedValue intValue];
5858
}
5959
[Instabug startWithToken:token invocationEvents:invocationEvents];
60-
60+
[Instabug setSdkDebugLogsLevel:sdkDebugLogsLevel];
61+
6162
RCTAddLogFunction(InstabugReactLogFunction);
6263
RCTSetLogThreshold(RCTLogLevelInfo);
6364

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export {
2424
Replies,
2525
Surveys,
2626
};
27+
export * from './utils/Enums';
2728

2829
export type { InstabugConfig };
2930
export type { Survey };

src/models/InstabugConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import type { invocationEvent } from '../utils/ArgsRegistry';
2+
import type { LogLevel } from '../utils/Enums';
23

34
export interface InstabugConfig {
5+
/**
6+
* The token that identifies the app. You can find it on your dashboard.
7+
*/
48
token: string;
9+
/**
10+
* An array of events that invoke the SDK's UI.
11+
*/
512
invocationEvents: invocationEvent[];
13+
/**
14+
* An optional LogLevel to indicate the verbosity of SDK logs. Default is Error.
15+
*/
16+
debugLogsLevel?: LogLevel;
617
}

src/modules/APM.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { logLevel } from '../utils/ArgsRegistry';
77
export { logLevel };
88

99
/**
10+
* @deprecated Pass a LogLevel to debugLogsLevel in Instabug.init instead.
11+
*
1012
* Sets the printed logs priority. Filter to one of the following levels:
1113
*
1214
* - `logLevelNone` disables all APM SDK console logs.

src/modules/Instabug.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
strings,
2323
welcomeMessageMode,
2424
} from '../utils/ArgsRegistry';
25+
import { LogLevel } from '../utils/Enums';
2526
import IBGEventEmitter from '../utils/IBGEventEmitter';
2627
import InstabugConstants from '../utils/InstabugConstants';
2728
import InstabugUtils, { stringifyIfNotString } from '../utils/InstabugUtils';
@@ -73,14 +74,17 @@ export const start = (token: string, invocationEvents: invocationEvent[]) => {
7374
* This is the main SDK method that does all the magic. This is the only
7475
* method that SHOULD be called.
7576
* Should be called in constructor of the AppRegistry component
76-
* @param token The token that identifies the app. You can find it on your dashboard.
77-
* @param invocationEvents The events that invoke the SDK's UI.
77+
* @param config SDK configurations. See {@link InstabugConfig} for more info.
7878
*/
7979
export const init = (config: InstabugConfig) => {
8080
InstabugUtils.captureJsErrors();
8181
NetworkLogger.setEnabled(true);
8282

83-
NativeInstabug.init(config.token, config.invocationEvents);
83+
NativeInstabug.init(
84+
config.token,
85+
config.invocationEvents,
86+
config.debugLogsLevel ?? LogLevel.Error,
87+
);
8488

8589
_isFirstScreen = true;
8690
_currentScreen = firstScreen;
@@ -137,6 +141,8 @@ export const setSessionProfilerEnabled = (isEnabled: boolean) => {
137141
};
138142

139143
/**
144+
* @deprecated Pass a {@link LogLevel} to debugLogsLevel in {@link init} instead. This will work on both Android and iOS.
145+
*
140146
* This API sets the verbosity level of logs used to debug The SDK. The default value in debug
141147
* mode is sdkDebugLogsLevelVerbose and in production is sdkDebugLogsLevelError.
142148
* @param level The verbosity level of logs.
@@ -400,6 +406,8 @@ export const clearAllUserAttributes = () => {
400406
};
401407

402408
/**
409+
* @deprecated Pass a {@link LogLevel} to debugLogsLevel in {@link init} instead. This will work on both Android and iOS.
410+
*
403411
* Enable/Disable debug logs from Instabug SDK
404412
* Default state: disabled
405413
*

src/utils/ArgsRegistry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { NativeInstabug } from '../native';
22

33
/**
4+
* @deprecated Pass a `LogLevel` to `debugLogsLevel` in `Instabug.init` instead.
5+
*
46
* Verbosity level of the SDK debug logs. This has nothing to do with IBGLog,
57
* and only affect the logs used to debug the SDK itself.
68
*/
@@ -12,6 +14,8 @@ export enum sdkDebugLogsLevel {
1214
}
1315

1416
/**
17+
* @deprecated Pass a `LogLevel` to `debugLogsLevel` in `Instabug.init` instead.
18+
*
1519
* APM Log Level.
1620
*/
1721
export enum logLevel {

src/utils/Enums.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NativeInstabug } from '../native';
2+
3+
export enum LogLevel {
4+
Verbose = NativeInstabug.sdkDebugLogsLevelVerbose,
5+
Debug = NativeInstabug.sdkDebugLogsLevelDebug,
6+
Error = NativeInstabug.sdkDebugLogsLevelError,
7+
None = NativeInstabug.sdkDebugLogsLevelNone,
8+
}

tests/modules/Instabug.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import waitForExpect from 'wait-for-expect';
88

99
import Report from '../../src/models/Report';
1010
import * as Instabug from '../../src/modules/Instabug';
11+
import { LogLevel } from '../../src/utils/Enums';
1112
import IBGEventEmitter from '../../src/utils/IBGEventEmitter';
1213
import IBGConstants from '../../src/utils/InstabugConstants';
1314
import InstabugUtils from '../../src/utils/InstabugUtils';
@@ -140,13 +141,15 @@ describe('Instabug Module', () => {
140141
const instabugConfig = {
141142
token: 'some-token',
142143
invocationEvents: [Instabug.invocationEvent.floatingButton, Instabug.invocationEvent.shake],
144+
debugLogsLevel: LogLevel.Debug,
143145
};
144146
Instabug.init(instabugConfig);
145147

146148
expect(NativeInstabug.init).toBeCalledTimes(1);
147149
expect(NativeInstabug.init).toBeCalledWith(
148150
instabugConfig.token,
149151
instabugConfig.invocationEvents,
152+
instabugConfig.debugLogsLevel,
150153
);
151154
});
152155

0 commit comments

Comments
 (0)