Winston: Winston mutating the params

Created on 22 Jan 2019  路  3Comments  路  Source: winstonjs/winston

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',

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

All 3 comments

See https://github.com/winstonjs/winston/issues/1549

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

there should be way to disable the params modification.

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

Was this page helpful?
0 / 5 - 0 ratings