@loglayer/transport-aws-cloudwatch-logs
v2.0.2
Published
AWS CloudWatch Logs logger transport for the LogLayer logging library
Maintainers
Readme
AWS CloudWatch Logs Logger Transport for LogLayer
A transport for the LogLayer logging library using the AWS CloudWatch Logs.
Installation
npm install loglayer @loglayer/transport-aws-cloudwatch-logs @aws-sdk/client-cloudwatch-logs serialize-errorUsage
import { LogLayer } from 'loglayer';
import { CloudWatchLogsTransport } from "@loglayer/transport-aws-cloudwatch-logs";
import { serializeError } from "serialize-error";
// Create LogLayer instance with CloudWatch Logs transport
const log = new LogLayer({
errorSerializer: serializeError,
transport: new CloudWatchLogsTransport({
// Set the log group and stream name to use.
groupName: "/loglayer/group",
streamName: "loglayer-stream-name",
}),
});
// Use LogLayer as normal
log.withMetadata({ customField: 'value' }).info('Hello from Lambda!');
// The transport formats messages as JSON with level, timestamp, data fields, and message
// Example output: {"level":"info","timestamp":1641013456789,"customField":"value","message":"Hello from Lambda!"}Documentation
For configuration options and examples, visit https://loglayer.dev/transports/aws-cloudwatch-logs
