Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Promptfoo Promptfoo Logger

From Leeroopedia
Knowledge Sources
Domains Logging, Observability
Last Updated 2026-02-14 07:45 GMT

Overview

Concrete tool for application-wide logging with Winston, providing automatic sanitization of sensitive fields, structured logging support, and file-based debug/error logging.

Description

The Logger module (logger.ts) wraps Winston to provide the primary logging interface for all promptfoo components. It supports four log levels (error, warn, info, debug), auto-sanitizes sensitive data (API keys, tokens, passwords) from log context objects, writes debug and error logs to rotating files, and supports structured JSON logging mode for machine-readable output. A log callback system allows the web UI to capture log messages in real time.

Usage

Import the default logger for all application logging. Use structured context objects for automatic sanitization of sensitive fields.

Code Reference

Source Location

Signature

export const LOG_LEVELS = {
  error: 0,
  warn: 1,
  info: 2,
  debug: 3,
} as const;

export interface SanitizedLogContext {
  url?: string;
  headers?: Record<string, string>;
  body?: unknown;
  queryParams?: Record<string, string>;
  [key: string]: unknown;
}

export function setLogCallback(callback: LogCallback | null): void
export function setStructuredLogging(enabled: boolean): void
export function initializeRunLogging(): void
export async function closeLogger(): Promise<void>

declare const logger: winston.Logger;
export default logger;

Import

import logger from './logger';
import { setLogLevel, LOG_LEVELS } from './logger';

I/O Contract

Inputs

Name Type Required Description
message string Yes Log message text
context SanitizedLogContext No Structured data (auto-sanitized)

Outputs

Name Type Description
console output string Formatted log message to stdout/stderr
debug log file File Debug-level logs written to ~/.promptfoo/logs/
error log file File Error-level logs written to ~/.promptfoo/logs/

Usage Examples

import logger from './logger';

// Basic logging
logger.info('Starting evaluation');
logger.debug('Processing test case', { testIdx: 0, provider: 'openai' });
logger.error('Provider call failed', { url: 'https://api.openai.com/v1/chat', error: 'timeout' });

// Context with sensitive data is auto-sanitized
logger.debug('API request', {
  headers: { Authorization: 'Bearer sk-secret123' },
  // Output: { headers: { Authorization: '[REDACTED]' } }
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment