Skip to content

Commit

Permalink
fix(logger): improve error logging structure (#2955)
Browse files Browse the repository at this point in the history
* fix(logger): improve error logging structure

- Enhance logging of error properties
- Capture name and stack for better debugging

(Your error handling was so vague, it could moonlight as a fortune cookie)

* refactor(logger): improve error property extraction in WinstonLogger

- Simplify error property extraction logic
- Use forEach instead of reduce for clarity and performance

(your error handling is starting to look like a messy breakup with too many exes)
  • Loading branch information
shanegrouber authored Jan 13, 2025
1 parent 7ca0f05 commit ab68ac3
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ export class WinstonLogger implements IAppLogger {
if (typeof error === 'string') {
this.logger.error({ message: error, ...payload });
} else {
this.logger.error({ error, ...payload });
const errorProperties: Record<string, unknown> = {};
Object.getOwnPropertyNames(error).forEach(key => {
errorProperties[key] = error[key as keyof Error];
});

const errorObj = {
...errorProperties,
message: error.message,
name: error.name,
stack: error.stack,
};

this.logger.error({ error: errorObj, ...payload });
}
}

Expand Down

0 comments on commit ab68ac3

Please sign in to comment.