{"size": 727, "ext": "js", "max_stars_repo_path": "middleware/logger.js", "max_stars_repo_name": "toddkh/tkhamilton", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "middleware/logger.js", "max_issues_repo_name": "toddkh/tkhamilton", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "middleware/logger.js", "max_forks_repo_name": "toddkh/tkhamilton", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.08, "max_line_length": 113, "alphanum_fraction": 0.7221458047}
import Logger from 'structure-logger'

module.exports = function loggerMiddleware(req, res, next) {
  const requestId = req.headers['x-request-id']

  req.logger = new Logger({
    applicationName: 'www.tkhamilton.com',
    namespace: 'default',
    requestId: requestId
  })

  req.logger.info(`${req.method} ${req.originalUrl}`)

  /*
  TODO:
  This needs to be updated as the logger instance is now defined per request

  We use a child here to both segregate logs by namespace and to also help with the fact that the request id
  will not be guaranteed to be correct on logs from this module
  */
  require('replicate-paradigm-api/lib/utilities').handleError.logger = req.logger.child('replicate-paradigm-api')

  next()
}
