- 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.
npm install @nuskin/mobile-logging- 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);
#### IMPORTANT INFORMATION:
- 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) and context (object - optional)message
- White/Default Terminal
- Info (logs locally)
- Accepts params (string - required) and context (object - optional)message
- Cyan
- Warning (will be pushed to Splunk and Firebase)
- Accepts params (string - required) and context (object - optional)message
- Yellow
- Error (logs locally and will be pushed to Splunk and Firebase Crashlytics)
- Accepts params (string - required), component (string - required), error (error - required), context (object - optional)event
- Red
- Event (Will be pushed to Splunk and Firebase ONLY)
- Accepts params (string - required), component (string - optional), context (object - optional)
- then add the logging as follows ():
``
Logger.
#### Example Usage:
```
Logger.error('Third party resource failed to return data', 'Home.tsx', error, {
market: 'US',
productId: 'us12345'
});
#### Example Output: