yidinghan / koa2-winston

koa2 version winston logger like express-winston
MIT License
38 stars 6 forks source link

Add support for reusing an existing winston logger instance #8

Closed ivansantosz closed 5 years ago

ivansantosz commented 5 years ago

Would be cool to be able to reuse an instance:

const logger = createLogger({
  format: format.combine(
    format.errors({ stack: true }),
    format.splat(),
    format.json()
  ),
  transports: [new transports.Console()],
});
yidinghan commented 5 years ago

Thank you for your reply!

You can simply pass logger as a parameter to the middleware

const consoleLogger = createLogger({
  format: format.combine(
    format.errors({ stack: true }),
    format.splat(),
    format.json(),
    format.prettyPrint(),
  ),
  transports: [new transports.Console()],
});
const middleware = logger({
  logger: consoleLogger,
});

Looking forward to your feedback