Logger

The Logger provider sends structured log entries to VCR's logging infrastructure, where they are visible in the instance logs on the dashboard.

Initialization

Node.js:

import { vcr, Logger } from '@vonage/vcr-sdk';

const session = vcr.createSession();
const logger = new Logger(session);

Python:

from vonage_cloud_runtime.vcr import VCR
from vonage_cloud_runtime.providers.logger.logger import Logger

vcr = VCR()
session = vcr.createSession()
logger = Logger(session)

API

Method Signature Description
log log(level, message, context?) Write a structured log entry

Log levels: info, warn, error, debug

The optional context argument accepts an object of additional key-value pairs that are attached to the log entry.

Example

Node.js:

import { vcr, Logger } from '@vonage/vcr-sdk';

const session = vcr.createSession();
const logger = new Logger(session);

await logger.log('info', 'User signed in', { userId: 'user-123' });
await logger.log('warn', 'Rate limit approaching', { remaining: 5 });
await logger.log('error', 'Payment failed', { orderId: 'order-456', reason: 'timeout' });

Session Convenience Method

The session object also exposes a log method as a shorthand:

session.log('info', 'User signed in', { userId: 'user-123' });

This is equivalent to creating a Logger instance and calling log on it.