import pino from "pino"; const isProduction = process.env["NODE_ENV"] === "production"; // In production, suppress Playwright debug output that bypasses pino. if (isProduction) { delete process.env["DEBUG"]; } const redactPaths: string[] = [ // Auth & credentials "**.cookie", "**.cookies", "**.set-cookie", "**.authorization", "**.password", "**.secret", // Tokens "**.token", "**.xsec_token", "**.access_token", "**.refresh_token", // API keys "**.api_key", "**.apikey", // Sessions "**.sessionid", "**.session_id", // Playwright StorageState structures "**.cookies[*].value", "**.origins[*].localStorage[*].value", ]; const errorSerializer = (err: Error): Record => { const serialized: Record = { type: err.constructor?.name ?? "Error", message: err.message, }; if (!isProduction && err.stack) { serialized["stack"] = err.stack; } return serialized; }; export const logger: pino.Logger = pino({ level: process.env["LOG_LEVEL"] ?? "info", redact: { paths: redactPaths, censor: "[REDACTED]", }, serializers: { err: errorSerializer, error: errorSerializer, }, ...(isProduction ? {} : { transport: { target: "pino-pretty", }, }), });