- This package will allow you to add custom logging in your React Native mobile application and send these logs to Splunk and Firebase all at once.
-
In a terminal, cd into the apps/{project-name} directory and run
yarn add @nuskin/mobile-logging
. -
Locate the top-level file
index.js
, insert the following code, replacing SPLUNK_RUM_REALM with actual Splunk REALM value, SPLUNK_RUM_ACCESS_TOKEN with actual Splunk Access Token, SPLUNK_APPLICATION_NAME with actual value of Splunk application name, SPLUNK_ENVIRONMENT with the app environment (ex: test, prod).
import { initSplunkLogger } from '@ns/mobile-logging';
//
/* INSERT BELOW
initSplunkLogger(
SPLUNK_RUM_REALM,
SPLUNK_RUM_ACCESS_TOKEN,
SPLUNK_APPLICATION_NAME,
SPLUNK_ENVIRONMENT,
buildVersion
);
*/
//
AppRegistry.registerComponent(appName, () => App);
- Please note that this package will send information to Firebase ONLY if you have already setup React Native Firebase for your app according to the instructions under 'Getting Started' here: https://rnfirebase.io/
- This package has a peer dependency for @splunk/otel-react-native and @react-native-firebase/analytics and @react-native-firebase/crashlytics. Make sure the app versions of these packages match those in this package or you will encounter issues.
- Anywhere within your app you would like to add logging, be sure to import
Logger
from@nuskin/mobile-logging
import { Logger } from '@nuskin/mobile-logging';
-
Use the following labels to indicate the kind of log being put in (note the colors listed - console will use these colors when logging output):
- Debug (logs locally)
- Accepts params
message
(string - required) andcontext
(object - optional) - White/Default Terminal
- Accepts params
- Info (logs locally)
- Accepts params
message
(string - required) andcontext
(object - optional) - Cyan
- Accepts params
- Warning (will be pushed to Splunk and Firebase)
- Accepts params
message
(string - required) andcontext
(object - optional) - Yellow
- Accepts params
- Error (logs locally and will be pushed to Splunk and Firebase Crashlytics)
- Accepts params
message
(string - required),component
(string - required),error
(error - required),context
(object - optional) - Red
- Accepts params
- Event (Will be pushed to Splunk and Firebase ONLY)
- Accepts params
event
(string - required),component
(string - optional),context
(object - optional)
- Accepts params
- Debug (logs locally)
-
then add the logging as follows ():
Logger.<log-type>(params);
Logger.error('Third party resource failed to return data', 'Home.tsx', error, {
market: 'US',
productId: 'us12345'
});