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

Winston mutating the params #1571

Closed
1 task
ankitsny opened this issue Jan 22, 2019 · 3 comments
Closed
1 task

Winston mutating the params #1571

ankitsny opened this issue Jan 22, 2019 · 3 comments

Comments

@ankitsny
Copy link

Please tell us about your environment:

  • winston version?
    • winston@3
  • _node -v outputs: v10.13.0
  • _Operating System Linux
  • _Language ES6

What is the problem?

Whenever I call logger.info(err) or any logger function then it adds level property in the params.

Example

const winston = require('winston');

const logger = winston.createLogger({
    transports: [
        new winston.transports.Console(),
    ]
});
const err = new Error('Error');
logger.info(err);
console.log('Console: ', err);
{"level":"info"}
Console:  { Error: [object Object]
    at Object.<anonymous> (/home/ankit/Desktop/play/winston.js:10:14)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
  level: 'info',
  [Symbol(level)]: 'info',
  [Symbol(message)]: '{"level":"info"}' }

Why winston is mutating the err object by adding level property in err object?

@kibertoad
Copy link
Contributor

See #1549

tl;dr -> performance reasons, works as designed.

@ankitsny
Copy link
Author

there should be way to disable the params modification.

@kibertoad
Copy link
Contributor

You can always do it yourself by using {...error}?..

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