Orchestration SDKs

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.

Configuring the log level in the Journey client
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.

logger() throws an error if native logger registration fails.

Wrap the call in a try/catch block if you need to handle this case:

Handling logger registration failure
try {
  const log = logger({ level: 'info' });
  // use log ...
} catch (error) {
  console.error('Failed to configure logger', error);
}

Log levels

The Orchestration SDK for React Native supports the following log levels:

Level Description

none

Disables all log output. This is the default when no level is specified.

error

Outputs error messages only.

warn

Outputs warning and error messages.

info

Outputs informational, warning, and error messages.

debug

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.

Native log levels

Internally, the JavaScript levels map to three native logger levels on Android and iOS:

JavaScript level Native level

debug, info

STANDARD

warn, error

WARN

none

NONE

Changing the log level at runtime

Call changeLevel() on the logger instance to update the level after initialisation. The change is applied to both the JavaScript and native layers immediately.

Changing the log level at runtime
log.changeLevel('debug');

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.

Redirecting SDK logs to a custom sink
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.