nest-winston icon indicating copy to clipboard operation
nest-winston copied to clipboard

Formatter fails on BigInt

Open SunMar opened this issue 2 years ago • 2 comments

Hi,

When trying to log an error object, the logger failed for me with the error: [unable to serialize, circular reference is too complex to analyze]

After debugging I found out that the problem was caused because the error object contained a BigInt and JSON.stringify() throws a TypeError if it encounters a BigInt. This was actually solved in winston/logform version 2.2.0 (https://github.com/winstonjs/logform/pull/84) by converting all BigInt's into strings, but nest-winston relies on fast-safe-stringify directly, so it doesn't have the benefit of this is fix.

https://github.com/gremo/nest-winston/blob/e82e927d004e81407983ff345441d489d4af0519/src/winston.utilities.ts#L37

Can nest-winston apply a similar fix for BigInt's, or possibly there is a way to let logform handle the stringification instead of calling fast-safe-stringify directly? I see for example logform also catches objects of type Buffer. Relying on logform might be more future proof, they can then take care of these edge cases.

Thank you for the easy integration of winston into Nest!

SunMar avatar Dec 21 '21 20:12 SunMar

Well, it seems quite easy. I'll push to master in the next few days I hope. Mind if I ask you to test it before releasing a new version?

gremo avatar Jan 03 '22 11:01 gremo

Sure, if you can provide some instructions on how I can test a branch/dev version I can easily run a quick test. I have some Node experience but never made any of my own libraries or used branch/dev versions so not sure how you can install them :)

SunMar avatar Jan 03 '22 11:01 SunMar

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 07 '23 01:07 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 14 '23 01:07 github-actions[bot]