const logger = require('../utils/logger')

module.exports = function requestLogger(req, res, next) {
    const start = Date.now()

    res.on('finish', () => {
        logger.info('请求完成', {
            method: req.method,
            path: req.originalUrl,
            statusCode: res.statusCode,
            durationMs: Date.now() - start,
            ip: req.ip,
        })
    })

    next()
}
