Skip to content

Commit 4373c0f

Browse files
Add APM.setLogLevel API
1 parent 17a9265 commit 4373c0f

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import static com.instabug.library.ui.onboarding.WelcomeMessage.State.DISABLED;
4646
import static com.instabug.library.ui.onboarding.WelcomeMessage.State.LIVE;
4747

48+
import static com.instabug.apm.model.LogLevel;
49+
4850
@SuppressWarnings({"SameParameterValue", "unchecked"})
4951
final class ArgsRegistry {
5052

@@ -65,6 +67,7 @@ final class ArgsRegistry {
6567
registerReproStepsModeArgs(ARGS);
6668
registerWelcomeMessageArgs(ARGS);
6769
registerInstabugFeatureRequestsActionTypes(ARGS);
70+
registerLogLevelArgs(ARGS);
6871
}
6972

7073

@@ -206,6 +209,15 @@ static void registerInstabugReportTypesArgs(Map<String, Object> args) {
206209
args.put("bugReportingReportTypeQuestion", BugReporting.ReportType.QUESTION);
207210
}
208211

212+
static void registerLogLevelArgs(Map<String, Object> args) {
213+
args.put("logLevelNone", LogLevel.NONE);
214+
args.put("logLevelError", LogLevel.ERROR);
215+
args.put("logLevelWarning", LogLevel.WARNING);
216+
args.put("logLevelInfo", LogLevel.INFO);
217+
args.put("logLevelDebug", LogLevel.DEBUG);
218+
args.put("logLevelVerbose", LogLevel.VERBOSE);
219+
}
220+
209221
static void registerInstabugExtendedBugReportModeArgs(Map<String, Object> args) {
210222
args.put("enabledWithRequiredFields", ExtendedBugReport.State.ENABLED_WITH_REQUIRED_FIELDS);
211223
args.put("enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ public String getName() {
3333
return "IBGAPM";
3434
}
3535

36+
/**
37+
* Sets the printed logs priority. Filter to one of the following levels.
38+
*
39+
* @param logLevel the priority level.
40+
*/
41+
@ReactMethod
42+
public void setLogLevel(final String logLevel) {
43+
MainThreadHandler.runOnMainThread(new Runnable() {
44+
@Override
45+
public void run() {
46+
try {
47+
if (ArgsRegistry.getDeserializedValue(logLevel, Integer.class) == null) {
48+
return;
49+
}
50+
APM.setLogLevel((int) ArgsRegistry.getRawValue(logLevel));
51+
} catch (Exception e) {
52+
e.printStackTrace();
53+
}
54+
}
55+
});
56+
}
57+
3658
/**
3759
* Enables or disables APM.
3860
* @param isEnabled boolean indicating enabled or disabled.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
8787

8888
private static final String TAG = RNInstabugReactnativeModule.class.getSimpleName();
8989

90+
//LogLevel
91+
private final String LOG_LEVEL_NONE = "logLevelNone";
92+
private final String LOG_LEVEL_ERROR = "logLevelError";
93+
private final String LOG_LEVEL_WARNING = "logLevelWarning";
94+
private final String LOG_LEVEL_INFO = "logLevelInfo";
95+
private final String LOG_LEVEL_DEBUG = "logLevelDebug";
96+
private final String LOG_LEVEL_VERBOSE = "logLevelVerbose";
97+
9098
//InvocationEvents
9199
private final String INVOCATION_EVENT_NONE = "invocationEventNone";
92100
private final String INVOCATION_EVENT_SHAKE = "invocationEventShake";
@@ -2360,6 +2368,14 @@ private void sendEvent(ReactApplicationContext reactContext,
23602368
@Override
23612369
public Map<String, Object> getConstants() {
23622370
final Map<String, Object> constants = new HashMap<>();
2371+
2372+
constants.put("logLevelNone", LOG_LEVEL_NONE);
2373+
constants.put("logLevelError", LOG_LEVEL_ERROR);
2374+
constants.put("logLevelWarning", LOG_LEVEL_WARNING);
2375+
constants.put("logLevelInfo", LOG_LEVEL_INFO);
2376+
constants.put("logLevelDebug", LOG_LEVEL_DEBUG);
2377+
constants.put("logLevelVerbose", LOG_LEVEL_VERBOSE);
2378+
23632379
constants.put("invocationEventNone", INVOCATION_EVENT_NONE);
23642380
constants.put("invocationEventShake", INVOCATION_EVENT_SHAKE);
23652381
constants.put("invocationEventScreenshot", INVOCATION_EVENT_SCREENSHOT);

index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export namespace APM {
138138
function startExecutionTrace(name: string): Trace;
139139
function startUITrace(name: string): void;
140140
function endUITrace(): void;
141+
function setLogLevel(logLevel: logLevel): void;
141142
}
142143
export function startWithToken(
143144
token: string,
@@ -285,6 +286,14 @@ export enum sdkDebugLogsLevel {
285286
sdkDebugLogsLevelError,
286287
sdkDebugLogsLevelNone,
287288
}
289+
export enum logLevel {
290+
logLevelNone,
291+
logLevelError,
292+
logLevelWarning,
293+
logLevelInfo,
294+
logLevelDebug,
295+
logLevelVerbose,
296+
}
288297
export enum extendedBugReportMode {
289298
enabledWithRequiredFields,
290299
enabledWithOptionalFields,

ios/RNInstabug/InstabugAPMBridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
+------------------------------------------------------------------------+
1212
*/
1313

14+
- (void)setLogLevel:(IBGLogLevel)_logLevel;
1415
- (void)setEnabled:(BOOL)isEnabled;
1516
- (void)setAppLaunchEnabled:(BOOL)isEnabled;
1617
- (void)setAutoUITraceEnabled:(BOOL)isEnabled;

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ - (NSDictionary *)constantsToExport
448448
@"bottomLeft": @(IBGPositionBottomLeft),
449449
@"topLeft": @(IBGPositionTopLeft),
450450

451+
@"logLevelNone": @(IBGLogLevelNone),
452+
@"logLevelError": @(IBGLogLevelError),
453+
@"logLevelWarning": @(IBGLogLevelWarning),
454+
@"logLevelInfo": @(IBGLogLevelInfo),
455+
@"logLevelDebug": @(IBGLogLevelDebug),
456+
@"logLevelVerbose": @(IBGLogLevelVerbose),
457+
451458
@"allActions": @(IBGActionAllActions),
452459
@"reportBugAction": @(IBGActionReportBug),
453460
@"requestNewFeature": @(IBGActionRequestNewFeature),

ios/RNInstabug/RCTConvert+InstabugEnums.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ @implementation RCTConvert (InstabugEnums)
101101
@"topLeft": @(IBGPositionTopLeft)
102102
}), IBGPositionBottomRight, integerValue);
103103

104+
RCT_ENUM_CONVERTER(IBGLogLevel, (@{
105+
@"logLevelNone": @(IBGLogLevelNone),
106+
@"logLevelError": @(IBGLogLevelError),
107+
@"logLevelWarning": @(IBGLogLevelWarning),
108+
@"logLevelInfo": @(IBGLogLevelInfo),
109+
@"logLevelDebug": @(IBGLogLevelDebug),
110+
@"logLevelVerbose": @(IBGLogLevelVerbose)
111+
}), IBGLogLevelInfo, integerValue);
112+
104113
RCT_ENUM_CONVERTER(IBGWelcomeMessageMode, (@{
105114
@"welcomeMessageModeLive": @(IBGWelcomeMessageModeLive),
106115
@"welcomeMessageModeBeta": @(IBGWelcomeMessageModeBeta),

modules/APM.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@ let { Instabug, IBGAPM } = NativeModules;
1111
* @exports APM
1212
*/
1313
export default {
14+
/**
15+
* Sets the printed logs priority. Filter to one of the following levels:
16+
*
17+
* - logLevelNone disables all APM SDK console logs.
18+
*
19+
* - logLevelError prints errors only, we use this level to let you know if something goes wrong.
20+
*
21+
* - logLevelWarning displays warnings that will not necessarily lead to errors but should be addressed nonetheless.
22+
*
23+
* - logLevelInfo (default) logs information that we think is useful without being too verbose.
24+
*
25+
* - logLevelDebug use this in case you are debugging an issue. Not recommended for production use.
26+
*
27+
* - logLevelVerbose use this only if logLevelDebug was not enough and you need more visibility
28+
* on what is going on under the hood.
29+
*
30+
* Similar to the logLevelDebug level, this is not meant to be used on production environments.
31+
*
32+
* Each log level will also include logs from all the levels above it. For instance,
33+
* logLevelInfo will include logLevelInfo logs as well as logLevelWarning
34+
* and logLevelError logs.
35+
36+
* @param {logLevel} the printed logs priority.
37+
*/
38+
setLogLevel(logLevel) {
39+
IBGAPM.setLogLevel(logLevel);
40+
},
41+
1442
/**
1543
* Enables or disables APM
1644
* @param {boolean} isEnabled

0 commit comments

Comments
 (0)