Skip to main content

express-access-log-middleware

An access and error logger for express based on pino-http

Usage

import * as express from 'express';
import jsLogger from '@map-colonies/js-logger';
import httpLogger from '@map-colonies/express-access-log-middleware';

const app = express()

const logger = jsLogger();

app.use(jsLogger({logger}));

app.get('/', (req,res) => {
res.json(hello: 'world');
});

app.listen(8080);

for more detailed usage check the pino-http documentation.

Configuration

nametypedefault valuedescription
loggerLoggerThe logger instance to use
ignorePathsstring[]undefinedThe paths to ignore logging
customLogLevel(res, err) => log_levelinfo for all under 500 statusA function to set the log level of a request
customSuccessMessage(res: ServerResponse) => stringundefinedfunction to set the success message
customSuccessObject(req: IncomingMessage, res: ServerResponse, val: any) => objectundefinedfunction to set the success object
customErrorMessage(error: Error, res: ServerResponse) => stringundefinedfunction to set the error message
customErrorObject(req: IncomingMessage, res: ServerResponse, error: Error) => objectundefinedfunction to set the error object
note

This page was generated from a remote source. you can find it on https://github.com/MapColonies/express-access-log-middleware/blob/master/README.md