Skip to content

Commit 21767b4

Browse files
author
Fran Montiel
committed
Add maximumLocalStorageSize as init argument
1 parent 5451bc0 commit 21767b4

5 files changed

Lines changed: 56 additions & 39 deletions

File tree

android/src/main/java/com/bugfender/react/RnBugfenderModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public void setForceEnabled(boolean value) {
6060
}
6161

6262
@ReactMethod
63-
public void setMaximumLocalStorageSize(Integer sizeInMB) {
64-
Bugfender.setMaximumLocalStorageSize(sizeInMB * 1024);
63+
public void setMaximumLocalStorageSize(Integer sizeInBytes) {
64+
Bugfender.setMaximumLocalStorageSize(sizeInBytes);
6565
}
6666

6767
@ReactMethod

example/src/App.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function App() {
2727
logBrowserEvents: true,
2828
})
2929
.native({
30+
maximumLocalStorageSize: 1024 * 1024,
3031
enableLogcatLogging: false,
3132
})
3233
.build()
@@ -93,13 +94,20 @@ export default function App() {
9394
const sec = date.getSeconds(); //Current Seconds
9495
throw new Error('Force crash' + 'Time: ' + hours + ':' + min + ':' + sec);
9596
}
97+
function sleep(ms) {
98+
return new Promise(resolve => setTimeout(resolve, ms));
99+
}
96100

97-
function _onPressButton(): void {
98-
Bugfender.sendLog({
99-
level: LogLevel.Debug,
100-
tag: 'REACT',
101-
text: 'Im being called from React!',
102-
});
101+
async function _onPressButton(): Promise<void> {
102+
while (true) {
103+
await sleep(10);
104+
105+
Bugfender.sendLog({
106+
level: LogLevel.Debug,
107+
tag: 'REACT',
108+
text: 'Im being called from React!',
109+
});
110+
}
103111

104112
Bugfender.log('Log without break lines in the middle of the message');
105113
Bugfender.log('Log with break lines \n\n in the middle of the message');

src/bugfender.ts

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { NativeModules, Platform } from 'react-native';
2-
import type { ISDKOptions } from './types/sdk-options';
3-
import type { UserFeedbackOptions, UserFeedbackResult } from './user-feedback';
4-
import { DefaultUserFeedbackOptions } from './user-feedback';
5-
import type { DeviceKeyValue } from './types/device';
6-
import type { ILogEntry } from './types/log';
7-
import { StringFormatter } from './string-formatter';
8-
import { LogLevel } from "./types/log";
9-
import { OverrideConsoleMethods } from "./override-console-methods";
10-
import { PrintToConsole } from "./print-to-console";
11-
import { SDKOptions } from "./sdk-options";
1+
import {NativeModules, Platform} from 'react-native';
2+
import type {ISDKOptions} from './types/sdk-options';
3+
import type {UserFeedbackOptions, UserFeedbackResult} from './user-feedback';
4+
import {DefaultUserFeedbackOptions} from './user-feedback';
5+
import type {DeviceKeyValue} from './types/device';
6+
import type {ILogEntry} from './types/log';
7+
import {StringFormatter} from './string-formatter';
8+
import {LogLevel} from "./types/log";
9+
import {OverrideConsoleMethods} from "./override-console-methods";
10+
import {PrintToConsole} from "./print-to-console";
11+
import {SDKOptions} from "./sdk-options";
1212

1313
const LINKING_ERROR =
1414
`The package '@bugfender/rn-bugfender' doesn't seem to be linked. Make sure: \n\n` +
15-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
15+
Platform.select({ios: "- You have run 'pod install'\n", default: ''}) +
1616
'- You rebuilt the app after installing the package\n' +
1717
'- You are not using Expo managed workflow\n';
1818

@@ -38,41 +38,46 @@ class BugfenderClass {
3838
if (!this.initialized) {
3939
const validatedOptions = this.sdkOptions.init(options);
4040

41-
// Needs to be executed prior initialization
41+
// region before init
4242
if (typeof options.deviceName !== 'undefined') {
4343
RnBugfender.overrideDeviceName(options.deviceName);
4444
}
45-
46-
// Library initialization
47-
Platform.OS === 'ios'
48-
? RnBugfender.activateLogger(validatedOptions.appKey)
49-
: RnBugfender.init(validatedOptions.appKey, false);
50-
5145
if (typeof validatedOptions.apiURL !== 'undefined') {
5246
RnBugfender.setApiUrl(validatedOptions.apiURL);
5347
}
54-
5548
if (typeof validatedOptions.baseURL !== 'undefined') {
5649
RnBugfender.setBaseUrl(validatedOptions.baseURL);
5750
}
51+
// endregion before init
5852

59-
if (validatedOptions.enableLogcatLogging) {
60-
RnBugfender.enableLogcatLogging();
61-
}
62-
63-
if (validatedOptions.logUIEvents) {
64-
RnBugfender.enableUIEventLogging();
65-
}
66-
67-
if (validatedOptions.registerErrorHandler) {
68-
RnBugfender.enableCrashReporting();
69-
}
53+
// region init
54+
Platform.OS === 'ios'
55+
? RnBugfender.activateLogger(validatedOptions.appKey)
56+
: RnBugfender.init(validatedOptions.appKey, false);
7057

7158
if (validatedOptions.overrideConsoleMethods) {
7259
this.overrideConsoleMethods.init(this.stringFormatter);
7360
}
7461

7562
this.printToConsole.init(validatedOptions.printToConsole ?? true);
63+
// endregion init
64+
65+
// region after init
66+
setTimeout(() => {
67+
if (validatedOptions.enableLogcatLogging) {
68+
RnBugfender.enableLogcatLogging();
69+
}
70+
if (validatedOptions.logUIEvents) {
71+
RnBugfender.enableUIEventLogging();
72+
}
73+
if (validatedOptions.registerErrorHandler) {
74+
RnBugfender.enableCrashReporting();
75+
}
76+
RnBugfender.setMaximumLocalStorageSize(
77+
validatedOptions.maximumLocalStorageSize
78+
);
79+
}, 2000); // Wait for BF to be initialized
80+
// endregion after init
7681

7782
this.initialized = true;
7883
}

src/sdk-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class SDKOptions {
2828
logUIEvents: true,
2929
registerErrorHandler: true,
3030
enableLogcatLogging: false,
31+
maximumLocalStorageSize: 5 * 1024 * 1024,
3132
...options,
3233
};
3334
}

src/types/sdk-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface ISDKWebOptions {
2929
}
3030

3131
export interface ISDKNativeOptions {
32+
/** Set the maximum size to store local log files in bytes (Native specific). Range accepted is from 1 MB to 50 MB. Defaults to 5 MB. **/
33+
maximumLocalStorageSize?: number;
3234
/** Logs all logs written via Logcat (Android specific). Defaults to `false`. */
3335
enableLogcatLogging?: boolean;
3436
}
@@ -68,6 +70,7 @@ export class SDKOptionsBuilder {
6870
build: this.webOptions?.build,
6971
version: this.webOptions?.version,
7072
enableLogcatLogging: this.nativeOptions?.enableLogcatLogging,
73+
maximumLocalStorageSize: this.nativeOptions?.maximumLocalStorageSize,
7174
};
7275

7376
removeUndefinedAttributes(options);

0 commit comments

Comments
 (0)