File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { redact } from "../../logger.js" ;
2+
13type StructuredArgs = ( Record < string , unknown > | undefined ) [ ] ;
24
35export interface StructuredLogger {
@@ -88,14 +90,14 @@ export class SimpleStructuredLogger implements StructuredLogger {
8890 level : string ,
8991 ...args : StructuredArgs
9092 ) {
91- const structuredLog = {
93+ const structuredLog = redact ( {
9294 timestamp : new Date ( ) ,
9395 message,
9496 $name : this . name ,
9597 $level : level ,
9698 ...this . fields ,
9799 ...( args . length === 1 ? args [ 0 ] : args ) ,
98- } ;
100+ } ) as Record < string , unknown > ;
99101
100102 if ( SimpleStructuredLogger . onLog ) {
101103 try {
Original file line number Diff line number Diff line change 11import { Logger , redact } from "../src/logger.js" ;
2+ import { SimpleStructuredLogger } from "../src/v3/utils/structuredLogger.js" ;
23
34function captureLogLine ( fn : ( ) => void ) : Record < string , any > {
45 const spy = vi . spyOn ( console , "info" ) . mockImplementation ( ( ) => { } ) ;
@@ -167,6 +168,26 @@ describe("Logger redaction", () => {
167168 } ) ;
168169} ) ;
169170
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 ( / ^ \[ f i l t e r e d / ) ;
184+ expect ( line . payload ) . toMatch ( / ^ \[ f i l t e r e d / ) ;
185+ expect ( line . apiKey ) . toMatch ( / ^ \[ f i l t e r e d / ) ;
186+ expect ( line . harmless ) . toBe ( "keep me" ) ;
187+ expect ( JSON . stringify ( line ) ) . not . toContain ( "should-not-appear" ) ;
188+ } ) ;
189+ } ) ;
190+
170191describe ( "redact()" , ( ) => {
171192 it ( "applies the same default deny-list and truncation as the Logger" , ( ) => {
172193 const result = redact ( {
You can’t perform that action at this time.
0 commit comments