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:Microsoft Playwright DebugLogger

From Leeroopedia

Template:Implementation Page

Overview

DebugLogger provides a structured debug logging system for Playwright's server internals, using the debug module with color-coded categories and optional file output.

Description

The DebugLogger class manages a collection of debug loggers, lazily creating them for each log category. Each category has a predefined color:

  • api (cyan), protocol (green), browser (reset), error (red)
  • channel (blue), server (cyan), socks (purple)
  • And more categories for install, download, recorder, etc.

When the DEBUG_FILE environment variable is set, all debug output is redirected to a file with ANSI escape codes stripped.

The module also provides RecentLogsCollector, a bounded log buffer that keeps the most recent log entries for inclusion in error reports.

Usage

Used throughout Playwright's server code for debug-level logging. Enabled via the DEBUG=pw:* environment variable.

Code Reference

Source Location

packages/playwright-core/src/server/utils/debugLogger.ts (96 lines)

Class Signatures

export type LogName = 'api' | 'protocol' | 'install' | 'download' | 'browser' | 'socks' | 'error' | 'channel' | 'server' | ...;

class DebugLogger {
  log(name: LogName, message: string | Error | object): void
  isEnabled(name: LogName): boolean
}

export const debugLogger: DebugLogger;

export class RecentLogsCollector {
  constructor()
  log(message: string): void
  recentLogs(): string[]
}

Import

import { debugLogger, RecentLogsCollector } from './server/utils/debugLogger';
import type { LogName } from './server/utils/debugLogger';

I/O Contract

Inputs

  • name: LogName -- the log category
  • message: string | Error | object -- the message to log

Outputs

  • Outputs to stderr via the debug module (when enabled)
  • Optionally writes to a file specified by DEBUG_FILE environment variable

Related Pages

Page Connections

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