How to use the morgan.compile function in morgan

To help you get started, we’ve selected a few morgan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RouteInjector / route-injector / lib / app / internals / express / ExpressMiddlewares.js View on Github external
// get the status code if response written
        var status = headersSent(res)
            ? res.statusCode
            : undefined;
        // get status color
        var color = status >= 500 ? 31 // red
            : status >= 400 ? 33 // yellow
                : status >= 300 ? 36 // cyan
                    : status >= 200 ? 32 // green
                        : 0; // no color
        // get colored function
        var fn = developmentFormatLine[color];
        if (!fn) {
            // compile
            // Avoid Typescript Error TS2339 (Morgan typings lacks compile)
            fn = developmentFormatLine[color] = logger.compile('\x1b[0m:method :url :body :user \x1b[' +
                color + 'm:status \x1b[0m:response-time ms - :res[content-length]\x1b[0m');
        }
        return fn(tokens, req, res);
    });
    //app.use(logger(':method :url :body :status :response-time ms - :res[content-length]'));

morgan

HTTP request logger middleware for node.js

MIT
Latest version published 5 years ago

Package Health Score

76 / 100
Full package analysis