AWS Lambda Powertools Transport
A LogLayer transport for AWS Lambda Powertools Logger.
Installation
Install the required packages:
sh
npm i loglayer @loglayer/transport-aws-lambda-powertools @aws-lambda-powertools/logger
sh
pnpm add loglayer @loglayer/transport-aws-lambda-powertools @aws-lambda-powertools/logger
sh
yarn add loglayer @loglayer/transport-aws-lambda-powertools @aws-lambda-powertools/logger
Setup
WARNING
The Logger utility from @aws-lambda-powertools/logger
must always be instantiated outside the Lambda handler.
typescript
import { Logger } from '@aws-lambda-powertools/logger';
import { LogLayer } from 'loglayer';
import { PowertoolsTransport } from '@loglayer/transport-aws-lambda-powertools';
// Create a new Powertools logger instance
const powertoolsLogger = new Logger({
serviceName: 'my-service',
logLevel: 'INFO'
});
// Create LogLayer instance with Powertools transport
const log = new LogLayer({
transport: new PowertoolsTransport({
logger: powertoolsLogger
})
});
// Use LogLayer as normal
log.withMetadata({ customField: 'value' }).info('Hello from Lambda!');
Log Level Mapping
LogLayer | Powertools |
---|---|
trace | DEBUG |
debug | DEBUG |
info | INFO |
warn | WARN |
error | ERROR |
fatal | ERROR |