> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Logging Configuration

> Configure logging for Portal SDK operations in the Web SDK with log levels and custom loggers.

The Portal Web SDK provides built-in logging capabilities to help you debug and monitor SDK operations during development and production. The interface matches the [React Native SDK](/sdks/react-native/guide/logging) for consistency across platforms.

## Quick Start

Enable logging by setting the `logLevel` parameter when initializing Portal:

```typescript theme={null}
import Portal from '@portal-hq/web'

const portal = new Portal({
  rpcConfig: {
    'eip155:1': 'https://...',
    'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'https://...',
  },
  apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
  logLevel: 'debug', // Enable debug-level logging
})
```

## Log Levels

The SDK supports five log levels, ordered by verbosity:

| Level     | Description                                               | Use Case                        |
| --------- | --------------------------------------------------------- | ------------------------------- |
| `'none'`  | No logging output (default)                               | Production environments         |
| `'error'` | Only errors and critical failures                         | Production with minimal logging |
| `'warn'`  | Errors and warnings                                       | Staging and production          |
| `'info'`  | Errors, warnings, and informational messages              | Development and staging         |
| `'debug'` | All log messages including detailed debugging information | Local development only          |

**Default:** `'none'` — No logs are emitted unless you explicitly configure logging.

### Logger Interface

Your custom logger must implement the `ILogger` interface (exported from `@portal-hq/web`):

```typescript theme={null}

interface ILogger {
  error: (...args: unknown[]) => void
  warn: (...args: unknown[]) => void
  info: (...args: unknown[]) => void
  debug: (...args: unknown[]) => void
}
```

### Custom logger example

```typescript theme={null}
import Portal from '@portal-hq/web'
import type { ILogger } from '@portal-hq/web'

const customLogger: ILogger = {
  error: (...args) => console.error('[MyApp]', ...args),
  warn: (...args) => console.warn('[MyApp]', ...args),
  info: (...args) => console.info('[MyApp]', ...args),
  debug: (...args) => console.debug('[MyApp]', ...args),
}

const portal = new Portal({
  rpcConfig: { /* ... */ },
  apiKey: 'your-api-key',
  logLevel: 'debug',
  logger: customLogger,
})
```

### Production logger with timestamps

For better observability, add timestamps to your logs:

```typescript theme={null}
const portalLogger: ILogger = {
  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({
  rpcConfig: { /* ... */ },
  apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
  logLevel: 'info',
  logger: portalLogger,
})
```

## 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.
4. **Fallback on logger errors** — If your logger throws, the SDK falls back to `console` for that call.

## Next Steps

* [MPC Progress Callbacks](/sdks/web/guide/mpc-progress-callbacks) — Monitor MPC operation progress
* [Portal API Methods](/sdks/web/guide/portal-api-methods) — Learn about available SDK methods
* [Error Codes](/resources/error-codes) — Understand Portal error codes
