@nuskin/mobile-logging
v3.1.1-3
Published
* This package will allow you to add custom logging in your React Native mobile application and send these logs to DataDog and Firebase all at once.
Downloads
3,485
Keywords
Readme
Mobile Logger Package
- This package will allow you to add custom logging in your React Native mobile application and send these logs to DataDog and Firebase all at once.
Install and setup
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 DD_CLIENT_TOKEN with your app's DataDog client token, CI_ENVIRONMENT_NAME with the app environment (ex: test, prod), and DD_RUM_APPLICATION_ID with your DataDog RUM App Id:
import { initLogger } from '@ns/mobile-logging';
//
// INSERT BELOW
initLogger(DD_CLIENT_TOKEN, CI_ENVIRONMENT_NAME, DD_RUM_APPLICATION_ID);
//
//
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 @datadog/mobile-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.
Usage
- 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 DataDog and Firebase)
- Accepts params
message
(string - required) andcontext
(object - optional) - Yellow
- Accepts params
- Error (logs locally and will be pushed to DataDog 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 DataDog 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);
Example Usage:
Logger.error('Third party resource failed to return data', 'Home.tsx', error, {
market: 'US',
productId: 'us12345'
});