alexgorbatchev / winston-child

Facilitates meta object inheritance for Winston loggers.
MIT License
4 stars 0 forks source link

WinstonChild(logger, {…}) modifies logger #1

Open msiebuhr opened 9 years ago

msiebuhr commented 9 years ago

Creating a child of a given logger actually modifies the parent logger, making sibling-loggers useless:

var logger = new Winston.Logger({transports: [new winston.transports.Console()]});
logger.info('test'); // outputs `info: test`
var child1 = new WinstonChild(logger, {child: 1});
logger.info('test'); // outputs `info: test child=1`
child1.info('test'); // outputs `info: test child=1`

I wouldn't expect logger.info(…) to have the child=1 metadata associated.

And it get's worse with a sibling logger:

var child2 = new WinstonChild(logger, {child: 2});
logger.info('test'); // outputs `info: test child=2`
child1.info('test'); // outputs `info: test child=2`
child2.info('test'); // outputs `info: test child=2`
msiebuhr commented 9 years ago

FYI - I ended up hacking a small shim around Winston that allows for inheritance in the way I originally expected: winston-context.