Middy access log middleware
Access log middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda
This middleware logs processed requests in an access log like fashion. I suggest using it together with @schibsted/middy-error-handler
This access log is optimised for JSON loggers e.g. bunyan or pino
Sets headers in after
and onError
phases.
Install
To install this middleware you can use NPM:
npm install --save @schibsted/middy-access-log
Options
-
logger
(defaults toconsole
) - a logging function that is invoked with the current error as an argument. You can passfalse
if you don't want the logging to happen. -
level
(defaults toinfo
) - log level to use for the log entries -
excludeHeaders
(array of header names, defaults to[]
) - prevent specified headers from showing up in logs (e.g. user credentials)
See the sample usage below.
Sample usage
const middy = require('@middy/core');
const accessLog = require('@schibsted/middy-access-log');
const bunyan = require('bunyan');
const logger = bunyan.createLogger({name: "myapp"});
const handler = middy(async () => ({
statusCode: 200,
body: JSON.stringify({ foo: 'bar' }),
}));
handler
.use(accessLog({ logger }));
Contributing
Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.