Winston: TypeError: logger.child is not a function

Created on 18 Jan 2019  ·  3Comments  ·  Source: winstonjs/winston

Please tell us about your environment:

  • _winston version?_

    • [ ] winston@2

    • [x] winston@3

  • _node -v outputs: v10.15.0
  • _Operating System? macOS
  • _Language? ES5/6

What is the problem?

const winston = require('winston');

const logger = winston.createLogger({
  transports: [new winston.transports.Console()],
});
logger.info('logger ok.');

const childLogger = logger.child({ test: 'test value' });
childLogger.info('child logger ok');

What do you expect to happen instead?

{"message":"logger ok.","level":"info"}
{"message":"child logger ok.","level":"info"}

Other information

TypeError: logger.child is not a function
    at Object.<anonymous> (/Users/onlybalance/test/logger.js:12:28)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

All 3 comments

function child() is only available in Winston 3.2.0 which wasn't released yet

how can i create child loggers in the meantime easily?

how can i create child loggers in the meantime easily?

@joernroeder
Now available. It has been updated yesterday.

Was this page helpful?
0 / 5 - 0 ratings