From 73927499436bef462b2e96c168ce222858c88db3 Mon Sep 17 00:00:00 2001 From: Stefano Sala Date: Thu, 16 Jan 2025 14:57:09 +0100 Subject: [PATCH] feat(logger): ensure error.cause is serialized --- src/logger.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/logger.ts b/src/logger.ts index 1d045ad9..dfb75661 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -127,7 +127,7 @@ export class Logger { // check if passed args is an object, if its not an object, add it to fields.args if (args instanceof Error) { - logEvent.fields = { ...logEvent.fields, message: args.message, stack: args.stack, name: args.name }; + logEvent.fields = { ...logEvent.fields, message: args.message, stack: args.stack, name: args.name, cause: args.cause }; } else if (typeof args === 'object' && args !== null && Object.keys(args).length > 0) { const parsedArgs = JSON.parse(JSON.stringify(args, jsonFriendlyErrorReplacer)); logEvent.fields = { ...logEvent.fields, ...parsedArgs }; @@ -353,6 +353,7 @@ function jsonFriendlyErrorReplacer(key: string, value: any) { name: value.name, message: value.message, stack: value.stack, + cause: jsonFriendlyErrorReplacer(undefined, value.cause), }; }