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

Field 'message' from logged object ignored by Winston #1486

Closed
1 of 2 tasks
YuriGor opened this issue Sep 30, 2018 · 2 comments
Closed
1 of 2 tasks

Field 'message' from logged object ignored by Winston #1486

YuriGor opened this issue Sep 30, 2018 · 2 comments

Comments

@YuriGor
Copy link

YuriGor commented Sep 30, 2018

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3.1.0
  • node -v outputs: v10.7.0
  • Operating System? Linux
  • Language? ES5

What is the problem?

looks like Winston ignores field with name message

const winston = require('winston');

const logger = winston.createLogger({
  level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
  format: winston.format.simple(),
  transports: [new winston.transports.Console()],
});

const email = {
  subject: 'Hello, World!',
  message: 'Hello mr.World, sorry, but you will not see this message in the console.',
};

console.log('console.log:', email);//works as expected
logger.debug('logger.debug: ', email);//no 'message'
console.log('console.log again:', email);//still works as expected

Output:

console.log: { subject: 'Hello, World!',
  message:
   'Hello mr.World, sorry, but you will not see this message in the console.' }
debug: logger.debug:  {"subject":"Hello, World!"}
console.log again: { subject: 'Hello, World!',
  message:
   'Hello mr.World, sorry, but you will not see this message in the console.' }

What do you expect to happen instead?

I expect all the object will be displayed in the log without sudden exceptions

@GeekyDeaks
Copy link

this is related to #1510 - if the first argument is an object, it gets Object.assign()d with the logging object which already has level and message elements, so either of those will get overwritten

@indexzero indexzero added this to To do in winston@3.2.0 Dec 7, 2018
indexzero added a commit that referenced this issue Dec 26, 2018
indexzero added a commit that referenced this issue Dec 26, 2018
* [doc] Document the solution to #1486.

* [doc] Show both in example.

* [doc] Update the examples.
@indexzero
Copy link
Member

Thank you for reporting this issue. The functionality is by design, but we updated examples & documentation in #1554 to make this less of a "gotcha". In this particular case if you use splat() you can get the behavior that you want:

const winston = require('winston');

const logger = winston.createLogger({
  level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
  format: winston.format.combine(
    winston.format.splat(),
    winston.format.simple()
  ),
  transports: [new winston.transports.Console()],
});

const email = {
  subject: 'Hello, World!',
  message: 'Hello mr.World, sorry, but you will not see this message in the console.',
};

logger.debug('logger.debug: %j', email);

This is very similar to the examples/splat-message.js that we added.

@indexzero indexzero moved this from To do to Done in winston@3.2.0 Dec 26, 2018
indexzero added a commit that referenced this issue Jan 26, 2019
…s). Fixes #1338, #1486 (#1562)

* [tiny dist] Whitespace. package-lock.json

* [test] Add E2E integration tests with logform `errors` format.

* [test] 5:00pm. Press return.

* [fix test] More E2E errors coverage.

* [test] Test custom error properties.

* [tiny doc] Make note of duplicate coverage in `logger`. Update minor formatting.

* [test] All E2E tests work except for one...

* [fix test doc] All 14 variations of handling `new Error()` now work as most folks expect.

* [tiny] Fix up file header.

* [dist] Bump to `logform@2.1.0`

* [fix tiny] Whitespace.

* s/req_id/requestId/

* [fix test] Address PR comments. Add test coverage for defaultMeta over .child(additionalMeta)
Mizumaki pushed a commit to Mizumaki/winston that referenced this issue Jun 11, 2020
* [doc] Document the solution to winstonjs#1486.

* [doc] Show both in example.

* [doc] Update the examples.
Mizumaki pushed a commit to Mizumaki/winston that referenced this issue Jun 11, 2020
…s). Fixes winstonjs#1338, winstonjs#1486 (winstonjs#1562)

* [tiny dist] Whitespace. package-lock.json

* [test] Add E2E integration tests with logform `errors` format.

* [test] 5:00pm. Press return.

* [fix test] More E2E errors coverage.

* [test] Test custom error properties.

* [tiny doc] Make note of duplicate coverage in `logger`. Update minor formatting.

* [test] All E2E tests work except for one...

* [fix test doc] All 14 variations of handling `new Error()` now work as most folks expect.

* [tiny] Fix up file header.

* [dist] Bump to `logform@2.1.0`

* [fix tiny] Whitespace.

* s/req_id/requestId/

* [fix test] Address PR comments. Add test coverage for defaultMeta over .child(additionalMeta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
winston@3.2.0
  
Done
Development

No branches or pull requests

3 participants