lambda-logger-middleware

1.0.3 • Public • Published

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'
    })
  }))

Readme

Keywords

Package Sidebar

Install

npm i lambda-logger-middleware

Weekly Downloads

11

Version

1.0.3

License

MIT

Unpacked Size

3.22 kB

Total Files

4

Last publish

Collaborators

  • eoinsha