import { Writable } from "node:stream"; import { describe, expect, it } from "vitest"; import { createLogger } from "../src/index"; function captureLog() { let output = ""; const destination = new Writable({ write(chunk, _encoding, callback) { output += chunk.toString(); callback(); }, }); return { destination, read: () => JSON.parse(output.trim()) as Record }; } describe("structured application logging", () => { it("emits service metadata and redacts credential fields", () => { const capture = captureLog(); const logger = createLogger("account-manager-test", { destination: capture.destination }); logger.info({ token: "secret-token", apiKey: "secret-key", operation: "test" }, "Test event"); expect(capture.read()).toMatchObject({ service: "account-manager-test", token: "[Redacted]", apiKey: "[Redacted]", operation: "test", msg: "Test event", }); }); });