Skip to content

Function: logging()

@providerprotocol/agents


@providerprotocol/agents / middleware / logging

logging(options): Middleware

Defined in: src/middleware/logging.ts:91

Creates a logging middleware that records agent execution activity.

This middleware provides comprehensive logging for agent operations including:

  • Execution start with agent identification
  • Execution completion with optional timing and token usage
  • Error conditions with contextual information
  • Optional detailed message content (debug level)

LoggingOptions = {}

Configuration options for logging behavior

Middleware

A configured Middleware instance

Basic usage with default options:

import { createAgent } from '@providerprotocol/agents';
import { logging } from '@providerprotocol/agents/middleware';
const agent = createAgent({
model: anthropic('claude-sonnet-4-20250514'),
middleware: [logging()],
});

Debug logging with message content:

const agent = createAgent({
model: anthropic('claude-sonnet-4-20250514'),
middleware: [
logging({
level: 'debug',
includeMessages: true,
includeTiming: true,
}),
],
});

Custom logger integration:

import pino from 'pino';
const pinoLogger = pino();
const agent = createAgent({
model: anthropic('claude-sonnet-4-20250514'),
middleware: [
logging({
level: 'info',
logger: (msg) => pinoLogger.info(msg),
}),
],
});