@daysmart/aws-lambda-logger
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

npm downloads npm bundle size (minified + gzip)

Usage

Create an instance of the logger at the top of your handler method and pass it through to anything that needs logging so that all logs remain connected by their awsRequestId.

Note: When logging typescript errors, it's recommended to wrap the error in the serializeError method so that everything is logged correctly. Errors thrown may be more complex than a simple typescript Error object and have complex properties that the logger won't pick up by default.

Starting with v1, this is an ESM package. You may have issues if you try to use it in a CommonJS package. Version 0.0.6 uses CommonJS but contains outdated dependencies. You can follow this guide to convert from a CommonJS package to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

...
import { createLogger, Logger, serializeError } from '@daysmart/aws-lambda-logger';
...

export const handlerMethod = async (event: any, context: any): Promise<any> => {
    let logger: Logger;

    try {
        logger = createLogger(!!(event?.debug || process.env.DEBUG), context.awsRequestId);
        ...
        logger.debug('event', { event: event });
        ...
    } catch (error) {
        logger?.error('handler_error', { error: serializeError(error) });
        ...
    }
};

Readme

Keywords

none

Package Sidebar

Install

npm i @daysmart/aws-lambda-logger

Weekly Downloads

13

Version

1.0.4

License

Apache-2.0

Unpacked Size

16.4 kB

Total Files

7

Last publish

Collaborators

  • automaticgiant
  • d.lindstrom
  • jordanrickmandaysmart
  • devendra.deshmukh
  • shafik23
  • aclebert
  • mohammed.radhi
  • pavitra.srinivasan
  • wmcintyre
  • mberryman_daysmart
  • daysmartgithubactions
  • taylorgarpow
  • daysmartadmin
  • nthornton2010
  • shereefz
  • jenelle.farris