Skip to content
Discussion options

You must be logged in to vote

It does not get passed to request object by default. There are two ways you could use your logger in controllers:

Solution 1

Export an instanciated logger, instead of the winston.createLogger function:

// logger.js

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  defaultMeta: { service: 'user-service' },
  transports: [
    new winston.transports.Console({
        format: winston.format.simple(),
    })
  ]
});

module.exports = logger;

Then you can import that logger in your controllers file whenever you need it:

// controller.js

const logger = require('./logger.js');

module.exports.controller = function som…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jeffreybradley1963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants