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]: splat formatter overrides message property, sometimes #189

Open
shawnjones253 opened this issue Jul 6, 2022 · 1 comment
Open

Comments

@shawnjones253
Copy link

shawnjones253 commented Jul 6, 2022

The problem

When using the splat formatter, handling of message properties in meta objects is different than without. Although the docs are technically correct in both cases, it seems weird that the behavior is different with and without splat.

Without splat, docs say meta objects are handled as follows (link):

NOTE: any { message } property in a meta object provided will automatically be concatenated to any msg already provided: For example the below will concatenate 'world' onto 'hello':

logger.log('error', 'hello', { message: 'world' });
logger.info('hello', { message: 'world' });

With splat, docs say meta objects are handled as follows (link):

Any additional splat parameters beyond those needed for the % tokens (aka "metas") are assumed to be objects. Their enumerable properties are merged into the info.

What version of Logform presents the issue?

v2.4.2

What version of Node are you using?

v14.16.1

If this worked in a previous version of Logform, which was it?

No response

Minimum Working Example

With splat

const logger = winston.createLogger({
  format: (() => {
    return combine(
      splat(),
      json()
    );
  })(),
  transports: [new winston.transports.Console()]
});

// looks contrived, but npm's `Request` package throws errors that looks like this
const err = {
  message: "msg2"
}
logger.error('msg1', err)

// outputs:
// {"level":"error","message":"msg2"}

Without splat

const logger = winston.createLogger({
  format: (() => {
    return combine(
      json()
    );
  })(),
  transports: [new winston.transports.Console()]
});

const err = {
  message: "msg2"
}
logger.error('msg1', err)

// outputs:
// {"level":"error","message":"msg1 msg2"}

EDIT: strangely, this problem doesn't occur with regular Error objects, even with splat (maybe because Error's properties are not enumerable?):

// boilerplate same as "with splat" from above

logger.error('msg1', new Error('msg2'))
// outputs: 
// {"level":"error","message":"msg1 msg2","stack":"Error: msg2 ..." }

Additional information

Maybe applicable to winstonjs/winston#2072

🔎 Search Terms

splat format message

@shawnjones253 shawnjones253 changed the title [Bug]: splat formatter overrides message property [Bug]: splat formatter overrides message property, sometimes Jul 6, 2022
@bertho-zero
Copy link

This is due to:

https://github.com/winstonjs/winston/blob/3998df01449da35a60cf4b90730b91f4b2466bc5/lib/winston/logger.js#L235-L255

This processing should not exist and should be done by format if desired.

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

No branches or pull requests

2 participants