text: const logger = require("../logger")
  
  module.exports = {
      logger(namespace) {
          return (req, res, next) => {
              const time = new Date().getTime()
              res.on('finish', () => {
                  const resDuration = new Date().getTime() - time
                  logger.info(namespace, `${req.method} ${req.url} ${resDuration}ms`, res.statusCode)
              })
              next()
          }
      },
      notFound(req, res, next) {
          const error = new Error(`Request to ${req.url} Not Found`)
          res.status(404)
  
          next(error)
      },
      error(namespace) {
          return (err, req, res, next) => {
              logger.error(namespace, 'Error', err)
              res.json({
                  message: err.message
              })
          }
      }
  }