Orchestration SDKs

Configuring logging in React Native

PingOne Advanced Identity Cloud PingAM PingOne 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 OIDC module for React Native.

Installing the logger module

The logger is provided by a separate package. Install it alongside @ping-identity/rn-oidc:

  • 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 createOidcClient() in the logger property.

Configuring the log level in the OIDC client
import { createOidcClient } from '@ping-identity/rn-oidc';
import { logger } from '@ping-identity/rn-logger';

const log = logger({ level: 'warn' });

const oidcClient = createOidcClient({
  clientId: '6c7eb89a-66e9-ab12-cd34-eeaf795650b2',
  discoveryEndpoint: 'https://auth.pingone.com/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration',
  redirectUri: 'org.forgerock.oidc://oauth2redirect',
  scopes: ['openid', 'email', 'address', 'profile'],
  logger: log,
});

The logger is registered with the native layer on both Android and iOS, so messages from the native OIDC 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.

Logging browser interactions

If you also install the Browser module to customize Custom Tabs or Auth Tabs behavior, you can pass the same logger instance into configureBrowser() to capture browser diagnostics:

Passing a logger to the Browser module
import { configureBrowser } from '@ping-identity/rn-browser';
import { logger } from '@ping-identity/rn-logger';

const browserLogger = logger({ level: 'debug' });

configureBrowser(
  {
    android: {
      customTabs: { showTitle: false },
    },
  },
  { logger: browserLogger },
);

Use a separate logger instance for the Browser module if you want to filter browser diagnostics independently from the rest of your application’s logging.