@@ -69,7 +69,7 @@ function getLoggingVariables(): ILoggingVariables {
69
69
} ;
70
70
}
71
71
72
- export function createNestLoggingModuleOptions ( settings : ILoggerSettings ) : Params {
72
+ export function createNestLoggingModuleOptions ( settings : { serviceName : string ; version : string } ) : Params {
73
73
const values : ILoggingVariables = getLoggingVariables ( ) ;
74
74
75
75
let redactFields : string [ ] = sensitiveFields . map ( ( val ) => val ) ;
@@ -99,7 +99,6 @@ export function createNestLoggingModuleOptions(settings: ILoggerSettings): Param
99
99
level : values . level ,
100
100
redact : {
101
101
paths : redactFields ,
102
- censor : customRedaction ,
103
102
} ,
104
103
base : {
105
104
pid : process . pid ,
@@ -116,32 +115,26 @@ export function createNestLoggingModuleOptions(settings: ILoggerSettings): Param
116
115
* To include these or any other custom props in mid-request logs,
117
116
* use `PinoLogger.assign(<props>)` explicitly before logging.
118
117
*/
119
- customProps : ( req : any , res : any ) => ( {
120
- user : {
121
- userId : req ?. user ?. _id || null ,
122
- environmentId : req ?. user ?. environmentId || null ,
123
- organizationId : req ?. user ?. organizationId || null ,
124
- apiServiceLevel : req ?. user ?. apiServiceLevel || null ,
125
- } ,
126
- authScheme : req ?. authScheme ,
127
- rateLimitPolicy : res ?. rateLimitPolicy ,
128
- } ) ,
118
+ customProps : ( req : any , res : any ) => {
119
+ /**
120
+ * This is a workaround to avoid duplicate keys in the final JSON log entry
121
+ * See https://github.com/pinojs/pino-http/issues/216
122
+ */
123
+ if ( req ?. user ) {
124
+ return {
125
+ user : {
126
+ userId : req ?. user ?. _id || null ,
127
+ environmentId : req ?. user ?. environmentId || null ,
128
+ organizationId : req ?. user ?. organizationId || null ,
129
+ apiServiceLevel : req ?. user ?. apiServiceLevel || null ,
130
+ } ,
131
+ authScheme : req ?. authScheme ,
132
+ rateLimitPolicy : res ?. rateLimitPolicy ,
133
+ } ;
134
+ }
135
+
136
+ return { } ;
137
+ } ,
129
138
} ,
130
139
} ;
131
140
}
132
-
133
- const customRedaction = ( value : any , path : string [ ] ) => {
134
- /*
135
- * Logger.
136
- * if (obj.email && typeof obj.email === 'string') {
137
- * obj.email = '[REDACTED]';
138
- * }
139
- *
140
- * return JSON.parse(JSON.stringify(obj));
141
- */
142
- } ;
143
-
144
- interface ILoggerSettings {
145
- serviceName : string ;
146
- version : string ;
147
- }
0 commit comments