Skip to content

Commit 1bf3cc8

Browse files
author
Fran Montiel
authored
Merge pull request #43 from bugfender/feature/maximumLocalStorageSize
Feature/maximum local storage size
2 parents 5451bc0 + 324bbed commit 1bf3cc8

6 files changed

Lines changed: 43 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Bugfender.init({
7575
// logUIEvents: true,
7676
// registerErrorHandler: true,
7777
// deviceName: 'Anonymous',
78+
// maximumLocalStorageSize: 5 * 1024 * 1024, // Native specific
7879
// enableLogcatLogging: false, // Android specific
7980
// logBrowserEvents: true, // Web specific
8081
// build: '42', // Web specific

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

3-
import { Button, Linking, StyleSheet, Text, View } from 'react-native';
4-
import { Bugfender, LogLevel, SDKOptionsBuilder } from '@bugfender/rn-bugfender';
3+
import {Button, Linking, StyleSheet, Text, View} from 'react-native';
4+
import {Bugfender, LogLevel, SDKOptionsBuilder} from '@bugfender/rn-bugfender';
55

66
export default function App() {
77

@@ -27,6 +27,7 @@ export default function App() {
2727
logBrowserEvents: true,
2828
})
2929
.native({
30+
maximumLocalStorageSize: 1024 * 1024,
3031
enableLogcatLogging: false,
3132
})
3233
.build()
@@ -94,7 +95,8 @@ export default function App() {
9495
throw new Error('Force crash' + 'Time: ' + hours + ':' + min + ':' + sec);
9596
}
9697

97-
function _onPressButton(): void {
98+
async function _onPressButton(): Promise<void> {
99+
98100
Bugfender.sendLog({
99101
level: LogLevel.Debug,
100102
tag: 'REACT',

src/bugfender.ts

Lines changed: 31 additions & 28 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,44 @@ 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
52+
53+
// region init
54+
Platform.OS === 'ios'
55+
? RnBugfender.activateLogger(validatedOptions.appKey)
56+
: RnBugfender.init(validatedOptions.appKey, validatedOptions.printToConsole ?? false);
57+
58+
if (validatedOptions.overrideConsoleMethods) {
59+
this.overrideConsoleMethods.init(this.stringFormatter);
60+
}
5861

62+
this.printToConsole.init(validatedOptions.printToConsole ?? true);
63+
// endregion init
64+
65+
// region after init
5966
if (validatedOptions.enableLogcatLogging) {
6067
RnBugfender.enableLogcatLogging();
6168
}
62-
6369
if (validatedOptions.logUIEvents) {
6470
RnBugfender.enableUIEventLogging();
6571
}
66-
6772
if (validatedOptions.registerErrorHandler) {
6873
RnBugfender.enableCrashReporting();
6974
}
70-
71-
if (validatedOptions.overrideConsoleMethods) {
72-
this.overrideConsoleMethods.init(this.stringFormatter);
73-
}
74-
75-
this.printToConsole.init(validatedOptions.printToConsole ?? true);
75+
RnBugfender.setMaximumLocalStorageSize(
76+
validatedOptions.maximumLocalStorageSize
77+
);
78+
// endregion after init
7679

7780
this.initialized = true;
7881
}

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)