1.0.3 • Published 5 years ago

lambda-logger-middleware v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

lambda-logger-middleware

license

A simple, configurable logging middleware for Middy.

This middleware logs events and responses using your logger's debug function and errors using its error function. The logger can be replaced (default is console) so you can configure your logger to log at the appropriate level.

Installation

npm install lambda-logger-middleware --save

Example using Pino

Pino is an excellent, fast, structured JSON logger. It can be configured with lambda-logger-middleware to only output DEBUG logs when you are running with STAGE=dev or with serverless-offline as follows.

const loggerMiddleware = require('lambda-logger-middleware')

function handler (event, context) { ... }

middy(handler)
  .use(loggerMiddleware({
    logger: pino({
      name: 'your-chosen-name',
      level: // Only output debug logs for offline and development environments
        process.env.IS_OFFLINE || process.env.STAGE === 'dev'
          ? 'debug'
          : 'info'
    })
  }))