|
1 | 1 | import { Logger, redact } from "../src/logger.js"; |
| 2 | +import { SimpleStructuredLogger } from "../src/v3/utils/structuredLogger.js"; |
2 | 3 |
|
3 | 4 | function captureLogLine(fn: () => void): Record<string, any> { |
4 | 5 | const spy = vi.spyOn(console, "info").mockImplementation(() => {}); |
@@ -167,6 +168,26 @@ describe("Logger redaction", () => { |
167 | 168 | }); |
168 | 169 | }); |
169 | 170 |
|
| 171 | +describe("SimpleStructuredLogger redaction", () => { |
| 172 | + it("redacts fields and arguments with the default deny-list", () => { |
| 173 | + const logger = new SimpleStructuredLogger("test"); |
| 174 | + |
| 175 | + const line = captureLogLine(() => |
| 176 | + logger.child({ headers: { authorization: "Bearer should-not-appear" } }).info("run started", { |
| 177 | + payload: { secret: "value" }, |
| 178 | + apiKey: "tr_prod_should_not_appear", |
| 179 | + harmless: "keep me", |
| 180 | + }) |
| 181 | + ); |
| 182 | + |
| 183 | + expect(line.headers).toMatch(/^\[filtered/); |
| 184 | + expect(line.payload).toMatch(/^\[filtered/); |
| 185 | + expect(line.apiKey).toMatch(/^\[filtered/); |
| 186 | + expect(line.harmless).toBe("keep me"); |
| 187 | + expect(JSON.stringify(line)).not.toContain("should-not-appear"); |
| 188 | + }); |
| 189 | +}); |
| 190 | + |
170 | 191 | describe("redact()", () => { |
171 | 192 | it("applies the same default deny-list and truncation as the Logger", () => { |
172 | 193 | const result = redact({ |
|
0 commit comments