Configuring logging in React Native
PingOne Advanced Identity Cloud PingAM React Native
When you develop applications with the Orchestration SDK, you might need to understand its internal workings or troubleshoot unexpected behavior.
Use logging to gain crucial insights into your application’s operations, identify issues, verify expected functionality, and better understand authentication flows.
This section covers how to configure and customize the logging output from the Orchestration SDK for React Native.
Installing the logger module
The logger is provided by a separate package.
Install it alongside @ping-identity/rn-journey:
-
yarn
-
npm
yarn add @ping-identity/rn-logger
npm install @ping-identity/rn-logger
After installation, run pod install in your ios/ directory to link the native dependencies on iOS:
cd ios && pod install
Configuring logging
To configure logging, create a logger instance with logger() from @ping-identity/rn-logger and pass it to createJourneyClient() in the logger property.
import { createJourneyClient } from '@ping-identity/rn-journey';
import { logger } from '@ping-identity/rn-logger';
const log = logger({ level: 'warn' });
const journeyClient = createJourneyClient({
serverUrl: 'https://openam-forgerock-sdks.forgeblocks.com/am',
realm: 'alpha',
cookie: 'ch15fefc5407912',
logger: log,
});
The logger is registered with the native layer on both Android and iOS, so messages from the native modules are routed through the same instance.
By default, logging is disabled (level: 'none') when no logger is provided.
|
Wrap the call in a Handling logger registration failure
|
Log levels
The Orchestration SDK for React Native supports the following log levels:
| Level | Description |
|---|---|
|
Disables all log output. This is the default when no level is specified. |
|
Outputs error messages only. |
|
Outputs warning and error messages. |
|
Outputs informational, warning, and error messages. |
|
Outputs all messages, including verbose diagnostic output intended for development. |
The Orchestration SDK outputs messages that have a priority equal to, or greater than your chosen level.
For example, setting the level to warn outputs both warn and error messages.
Customizing logging output
By default, the Orchestration SDK writes messages to the standard JavaScript console, for example console.log, and console.warn.
To redirect log output, for example to a crash reporting service or a structured logging library, provide a custom object when creating the logger.
Each method receives the log arguments and must return true to indicate that the message was handled.
import { logger } from '@ping-identity/rn-logger';
const log = logger({
level: 'debug',
custom: {
error: (...args) => { sendToReportingService('error', args); return true; },
warn: (...args) => { sendToReportingService('warn', args); return true; },
info: (...args) => { sendToReportingService('info', args); return true; },
debug: (...args) => { sendToReportingService('debug', args); return true; },
},
});
If the custom configuration is omitted, the Orchestration SDK for React Native falls back to the default console methods.