All files / src/lib/middleware request-logger.ts

72.73% Statements 8/11
0% Branches 0/1
66.67% Functions 2/3
72.73% Lines 8/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2061x       61x 151x 151x 151x 755x           755x       61x  
import url from 'url';
import { RequestHandler } from 'express';
import { IUnleashConfig } from '../types/option';
 
const requestLogger: (config: IUnleashConfig) => RequestHandler = (config) => {
    const logger = config.getLogger('HTTP');
    const enable = config.server.enableRequestLogger;
    return (req, res, next) => {
        Iif (enable) {
            res.on('finish', () => {
                const { pathname } = url.parse(req.originalUrl);
                logger.info(`${res.statusCode} ${req.method} ${pathname}`);
            });
        }
        next();
    };
};
 
export default requestLogger;