@schibsted/middy-access-log

4.0.2 • Public • Published

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.

Package Sidebar

Install

npm i @schibsted/middy-access-log

Weekly Downloads

74

Version

4.0.2

License

MIT

Unpacked Size

27.3 kB

Total Files

15

Last publish

Collaborators

  • nicolai-schibsted
  • katarzynapalka
  • johand199
  • rodbiffi
  • mike-dvtka
  • spp-owner
  • filipgolonka
  • schibstedbot
  • joawan
  • gustavkj
  • pakerstrand