Skip to main content
The Portal SDK for React Native provides built-in logging capabilities to help you debug and monitor SDK operations during development and production.

Quick Start

Enable logging by setting the logLevel parameter when initializing Portal:
import { Portal } from '@portal-hq/core'

const portal = new Portal({
  apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
  logLevel: 'debug', // Enable debug-level logging
  backup: { /* ... */ },
  gatewayConfig: { /* ... */ },
})

Log Levels

The SDK supports five log levels, ordered by verbosity:
LevelDescriptionUse Case
'none'No logging output (default)Production environments
'error'Only errors and critical failuresProduction with minimal logging
'warn'Errors and warningsStaging and production
'info'Errors, warnings, and informational messagesDevelopment and staging
'debug'All log messages including detailed debugging informationLocal development only
Default: 'none' - No logs are emitted unless you explicitly configure logging.

Logger Interface

Your custom logger must implement these four methods:
interface Logger {
  error: (...args: unknown[]) => void
  warn: (...args: unknown[]) => void
  info: (...args: unknown[]) => void
  debug: (...args: unknown[]) => void
}

Production Logger with Timestamps

For better observability, add timestamps to your logs:
const portalLogger = {
  error: (...args: unknown[]) => {
    const timestamp = new Date().toISOString()
    console.error(`[${timestamp}] [PORTAL ERROR]`, ...args)
  },
  warn: (...args: unknown[]) => {
    const timestamp = new Date().toISOString()
    console.warn(`[${timestamp}] [PORTAL WARN]`, ...args)
  },
  info: (...args: unknown[]) => {
    const timestamp = new Date().toISOString()
    console.info(`[${timestamp}] [PORTAL INFO]`, ...args)
  },
  debug: (...args: unknown[]) => {
    const timestamp = new Date().toISOString()
    console.debug(`[${timestamp}] [PORTAL DEBUG]`, ...args)
  },
}

const portal = new Portal({
  apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
  logLevel: 'info',
  logger: portalLogger,
  backup: { /* ... */ },
  gatewayConfig: { /* ... */ },
})

How Logging Works

  1. SDK handles level filtering - The SDK filters messages based on your logLevel setting before calling your logger methods
  2. Logger handles output - Your logger is responsible only for formatting and outputting the messages
  3. No performance impact when disabled - When logLevel is 'none', log messages are not generated

Next Steps