-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: this.logger.log(new Error())
prints empty object
#526
Comments
I tried logging the error in NestJS using JSON mode false and I got this result [2021-03-17T14:01:37.358Z] [INFO] [Macs-Mac-mini.local] [NestJS] 7346 [UserService]
{} |
jmcdo29
added a commit
that referenced
this issue
Apr 2, 2021
`Error`s in JavaScript are Objects with non-enumerable properties meaning that `JSON.stringify()` returns `{}`. With the new fix errors no longer are stringified and printed how they are by default printed when using `process.stdout.write()`. ```ts process.stdout.write(new Error('This is an error'); // Error: This is an error ``` This should make for cleaner logic and better integration with the NestJS framework. Also, the assignment of `this.pid` and `this.hostname` has been moved up in the constructor to accomodate bad log levels. PID is now also wrapped in `[]` instead of printed directly, to be more consistent with the stream logger. fix #526
jmcdo29
added a commit
that referenced
this issue
Apr 2, 2021
`Error`s in JavaScript are Objects with non-enumerable properties meaning that `JSON.stringify()` returns `{}`. With the new fix errors no longer are stringified and printed how they are by default printed when using `process.stdout.write()`. ```ts process.stdout.write(new Error('This is an error'); // Error: This is an error ``` This should make for cleaner logic and better integration with the NestJS framework. Also, the assignment of `this.pid` and `this.hostname` has been moved up in the constructor to accomodate bad log levels. PID is now also wrapped in `[]` instead of printed directly, to be more consistent with the stream logger. fix #526
jmcdo29
added a commit
that referenced
this issue
Apr 11, 2021
`Error`s in JavaScript are Objects with non-enumerable properties meaning that `JSON.stringify()` returns `{}`. With the new fix errors no longer are stringified and printed how they are by default printed when using `process.stdout.write()`. ```ts process.stdout.write(new Error('This is an error'); // Error: This is an error ``` This should make for cleaner logic and better integration with the NestJS framework. Also, the assignment of `this.pid` and `this.hostname` has been moved up in the constructor to accomodate bad log levels. PID is now also wrapped in `[]` instead of printed directly, to be more consistent with the stream logger. fix #526
jmcdo29
added a commit
that referenced
this issue
Jun 20, 2021
`Error`s in JavaScript are Objects with non-enumerable properties meaning that `JSON.stringify()` returns `{}`. With the new fix errors no longer are stringified and printed how they are by default printed when using `process.stdout.write()`. ```ts process.stdout.write(new Error('This is an error'); // Error: This is an error ``` This should make for cleaner logic and better integration with the NestJS framework. Also, the assignment of `this.pid` and `this.hostname` has been moved up in the constructor to accomodate bad log levels. PID is now also wrapped in `[]` instead of printed directly, to be more consistent with the stream logger. fix #526
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Current behavior
If an
Error
instance is passed to any logger method other thanprintError
, the printed log is an empty object{}
Input Code
Expected behavior
The logger should log the error message and error name.
Possible Solution
Make sure, before running
typeof message === 'object'
that the message isn't an error object.Environment
The text was updated successfully, but these errors were encountered: