Enhance logger to handle Error objects separately in debug mode

- Modified the logger to check if the data is an instance of Error.
- If it is an Error, the logger now formats the output to include the message and stack trace in debug mode, or just the message otherwise.
- Retained the existing behavior for other object types in debug mode.
This commit is contained in:
Alex Newman
2025-12-27 21:55:20 -05:00
parent 64328d4120
commit 949b845992
9 changed files with 85 additions and 64 deletions
+6 -1
View File
@@ -237,7 +237,12 @@ class Logger {
// Build data part
let dataStr = '';
if (data !== undefined && data !== null) {
if (this.getLevel() === LogLevel.DEBUG && typeof data === 'object') {
// Handle Error objects specially - they don't JSON.stringify properly
if (data instanceof Error) {
dataStr = this.getLevel() === LogLevel.DEBUG
? `\n${data.message}\n${data.stack}`
: ` ${data.message}`;
} else if (this.getLevel() === LogLevel.DEBUG && typeof data === 'object') {
// In debug mode, show full JSON for objects
dataStr = '\n' + JSON.stringify(data, null, 2);
} else {