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:
+6
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user