1.0.4 • Published 1 year ago

@daysmart/aws-lambda-logger v1.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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) });
        ...
    }
};
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.3

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago