Implementation:Promptfoo Promptfoo Logger Browser
| Knowledge Sources | |
|---|---|
| Domains | Logging, Browser |
| Last Updated | 2026-02-14 07:45 GMT |
Overview
Lightweight browser-compatible logger that mirrors the Node.js logger API surface, used in web UI builds via Vite aliasing.
Description
The Logger_Browser module (logger.browser.ts) provides a minimal console-based logging implementation that matches the same API as the full Winston-based Node logger. It supports four log levels (error, warn, info, debug), basic sensitive field sanitization (redacting keys, secrets, tokens, passwords), and no-op stubs for Node-specific features (transports, file logging, source maps). Vite aliases this module in place of ./logger for browser builds.
Usage
This module is not imported directly. It is aliased by Vite when building the browser (web UI) bundle, replacing ./logger to avoid Node.js dependencies.
Code Reference
Source Location
- Repository: Promptfoo_Promptfoo
- File: src/logger.browser.ts
- Lines: 1-126
Signature
export const LOG_LEVELS = { error: 0, warn: 1, info: 2, debug: 3 } as const;
export function getLogLevel(): LogLevel
export function setLogLevel(level: LogLevel): void
export function isDebugEnabled(): boolean
export function setLogCallback(cb: ((msg: string) => void) | null): void
declare const logger: {
error: (msg: string, ctx?: Record<string, unknown>) => void;
warn: (msg: string, ctx?: Record<string, unknown>) => void;
info: (msg: string, ctx?: Record<string, unknown>) => void;
debug: (msg: string, ctx?: Record<string, unknown>) => void;
level: string;
};
export default logger;
Import
// Aliased automatically by Vite; not imported directly
import logger from './logger'; // resolves to logger.browser.ts in browser builds
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| message | string | Yes | Log message |
| context | Record<string, unknown> | No | Context object (sensitive fields auto-redacted) |
Outputs
| Name | Type | Description |
|---|---|---|
| console output | void | Messages written to browser console |
Usage Examples
import logger from './logger'; // Resolves to browser logger in web UI
logger.info('Page loaded');
logger.debug('API response', { data: response, apiKey: 'sk-secret' });
// apiKey will be redacted to '[REDACTED]'