Skip to content

Middy middleware for logging processed requests in an access-log like fashion. Optimised for JSON loggers e.g. Bunyan or Pino.

License

Notifications You must be signed in to change notification settings

schibsted/middy-access-log

Repository files navigation

Middy access log middleware

github checks current version @ npm weekly downloads @ npm minified size

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 to console) - a logging function that is invoked with the current error as an argument. You can pass false if you don't want the logging to happen.
  • level (defaults to info) - 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.

About

Middy middleware for logging processed requests in an access-log like fashion. Optimised for JSON loggers e.g. Bunyan or Pino.

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •