LambdaLog is a lightweight and performant logging library for Node.js applications, primarily optimized for AWS Lambda environments. It specializes in generating structured JSON logs, making them easily parseable and searchable by services like CloudWatch Logs and other log aggregation platforms. The current stable version is 3.1.0, released in October 2021. While a 4.x beta series was active in late 2021 introducing ESM support and TypeScript improvements, development appears to have slowed since. Key differentiators include its seamless integration with Lambda execution contexts, automatic metadata enrichment, and a robust error logging mechanism, providing a production-ready alternative to `console.log` for serverless applications. It aims for minimal overhead and provides configurable logging levels and dynamic metadata capabilities.
npm install lambda-logVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic logging, error handling, warning messages, and custom configuration with metadata, suitable for a TypeScript AWS Lambda function.
Refer to the official v4.0.0 release notes and migration guide once available. Avoid using beta versions in production. Stay on v3.x until a stable v4 is released and a clear upgrade path is provided.
Avoid using `addLevel()`. If custom log levels are critical for your workflow, consider implementing a custom formatter or pre-processing step for your logs outside of `lambda-log`.
Ensure your build process or Node.js environment is configured to correctly resolve ESM imports. For direct Node.js ESM usage with v4+, you may need to add `.js` extensions to your imports (e.g., `import { LambdaLog } from 'lambda-log/lib/LambdaLog.js';`).Ensure correct module resolution and destructuring for `EventEmitter` if you're working with custom extensions that rely on it, or update to a newer beta/stable release where this fix has been applied (v4.0.0-beta.4 and later).
Upgrade to v3.0.2 or later, which includes a fix to skip adding a `toJSON` method if one already exists. If using an older version, refactor your custom error handling to avoid direct manipulation of `toJSON` or configure `lambda-log` to not serialize errors in a conflicting manner.
For v4.x, ensure you are using ESM `import` statements. If experiencing resolution issues, confirm your `tsconfig.json` (if TypeScript) and `package.json` (`type: 'module'`) are correctly configured for ESM. As a workaround, try explicit `.js` extensions in your import paths: `import { LambdaLog } from 'lambda-log/lib/LambdaLog.js';`.No dependency data recorded yet.