Skip to content
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

Closed
jmcdo29 opened this issue Mar 15, 2021 · 1 comment · Fixed by #530
Closed

[Bug]: this.logger.log(new Error()) prints empty object #526

jmcdo29 opened this issue Mar 15, 2021 · 1 comment · Fixed by #530

Comments

@jmcdo29
Copy link
Owner

jmcdo29 commented Mar 15, 2021

Bug Report

Current behavior

If an Error instance is passed to any logger method other than printError, the printed log is an empty object {}

Input Code

const { Ogma } = require('@ogma/logger');
const ogma = new Ogma();
ogma.log(new Error('I want to see this'));

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


@ogma/logger version: 1.0.0
@jonatasfernandespimenta

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants