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

info.message is concatenated with meta.message as is #1739

Closed
1 of 2 tasks
Damaged-Organic opened this issue Dec 2, 2019 · 2 comments · Fixed by #1740
Closed
1 of 2 tasks

info.message is concatenated with meta.message as is #1739

Damaged-Organic opened this issue Dec 2, 2019 · 2 comments · Fixed by #1740

Comments

@Damaged-Organic
Copy link

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v8.9.4
  • Operating System? Linux
  • Language? ES6/7

What is the problem?

If meta argument of a log method (destructured from splat rest parameters) is an Error-like object (e.g. having a message property), the original msg argument is concatenated with meta.message without any spaces, making the output unreadable.

Working example:

const { format, transports, createLogger } = require('winston')

const consoleTransport = new transports.Console({
  // General settings
  level: 'silly',
  format: format.combine(
    format.simple()
  )
})

const logger = createLogger({
  level: 'silly',
  transports: [consoleTransport]
})

logger.error('Description of other error', new Error('Other error'))

Example output:

error: Description of other errorOther error {"stack":"Error: Other error\n    at Object.<anonymous> (.../src/test.js:16:44)\n    at Module._compile (module.js:643:30)\n    at Object.Module._extensions..js (module.js:654:10)\n    at Module.load (module.js:556:32)\n    at tryModuleLoad (module.js:499:12)\n    at Function.Module._load (module.js:491:3)\n    at Function.Module.runMain (module.js:684:10)\n    at startup (bootstrap_node.js:187:16)\n    at bootstrap_node.js:608:3"}

What do you expect to happen instead?

The logged message is separated from the meta Error object message:

error: Description of other error Other error {"stack":"Error: Other error\n    at Object.<anonymous> (.../src/test.js:16:44)\n    at Module._compile (module.js:643:30)\n    at Object.Module._extensions..js (module.js:654:10)\n    at Module.load (module.js:556:32)\n    at tryModuleLoad (module.js:499:12)\n    at Function.Module._load (module.js:491:3)\n    at Function.Module.runMain (module.js:684:10)\n    at startup (bootstrap_node.js:187:16)\n    at bootstrap_node.js:608:3"}

Other information

The problem is really within the log method:

if (meta.message) info.message += `${meta.message}`;

Simply concatenating like that will definitely produce strange results. Having something like that will solve the problem:

if (meta.message) info.message = `${info.message} ${meta.message}`;

The best thing would be to not concatenate messages at all, having separate stack and meta object itself on the info.

@jfirebaugh
Copy link

Previously reported in #1634.

@DABH
Copy link
Contributor

DABH commented Jun 22, 2020

Closing as duplicate -- fixing though...

@DABH DABH closed this as completed Jun 22, 2020
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.

3 participants