middy-console-logger

1.0.0 • Public • Published

middy-console-logger

Middy middleware for filtering logs printed over console logging methods (trace, debug, info, log, warn, error). If the level of the console logging method is equal or bigger than configured level, the log is printed, Otherwise, it is ignored.

You can find the supported log levels and their orders in the following table:

Log Level Name Log Level
NONE 0
TRACE 1
DEBUG 2
INFO 3
LOG 3
WARN 4
ERROR 5

Note: The default log level is NONE and which means that all the logs are printed by default if you don't configure any log level threshold.

Installation

To install the middleware, you can use NPM:

npm install --save middy-console-logger

Note: Requires @middy/core version 2.0.0+

Usage

  • Register middy-console-logger middleware in your handler:
const middy = require('@middy/core');
const consoleLogger = require('middy-console-logger');

const handler = async(event, context) => {
  // Do something meaningful

  return {
    statusCode: 200,
  }
}

module.exports.handler = middy(handler).use(consoleLogger());
  • Configure log level by environment variable or options passed to middleware:

    • By environment variable: Set MIDDY_CL_LOG_LEVEL environment variable to any supported log level.
    MIDDY_CL_LOG_LEVEL=INFO
    
    • By options: Pass the log level through options.
    const consoleLogger = require('middy-console-logger');
    
    module.exports.handler = middy(handler).use(consoleLogger({logLevel: 'INFO'}));

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License.

Package Sidebar

Install

npm i middy-console-logger

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

7.38 kB

Total Files

5

Last publish

Collaborators

  • serkan-ozal