2.0.1 • Published 1 year ago

@map-colonies/express-access-log-middleware v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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
customErrorMessage(error: Error, res: ServerResponse) => stringundefinedfunction to set the success message