Skip to content

Commit 04040f2

Browse files
authored
Tweak handling of DO_NOT_LOG in production. (#600)
1 parent 756746c commit 04040f2

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

libs/lib-services/src/logger/Logger.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ export const DO_NOT_LOG = Symbol('DO_NOT_LOG');
2929
*/
3030
const logFilter = (key: string, value: unknown) => {
3131
if (value != null && typeof value == 'object' && (value as any)[DO_NOT_LOG]) {
32-
throw new ServiceAssertionError(`${Object.getPrototypeOf(value)?.constructor?.name} must not be logged`);
32+
const name = Object.getPrototypeOf(value)?.constructor?.name;
33+
const message = `${key}: ${name} must not be logged`;
34+
if (process.env.NODE_ENV == 'production') {
35+
// In production, log a warning and filter out the value.
36+
// We do this in case a DO_NOT_LOG value is only logged in rare edge cases not covered by tests,
37+
// and we don't want to cause cascading failures in that case.
38+
logger.error(message);
39+
return undefined;
40+
}
41+
// In local development and testing, this is a hard error to surface the issue clearly.
42+
throw new ServiceAssertionError(message);
3343
}
3444
return value;
3545
};

0 commit comments

Comments
 (0)