Logging is one of the most important aspects of software development and it's important to have sufficient logging for proper debugging and tracking. Given that the default option for storing logs for Lambda is CloudWatch Logs in AWS, it's best to format your logs in a manner than is easily readable and searchable within the interface. By providing a JSON-formatted string instead of plain text, CloudWatch is able to parse the content and make it searchable based on its properties. Like all logging solutions, it only works if the log data is provided in all the same structure.
Lambda Log was created as a basic logging mechanism that allows the developer to log to the
console but also format that data to a JSON string that keeps each log consistent and easily searchable within CloudWatch Logs. While the name of the package implies "Lambda", this package may be used in other Node processes running on AWS such as ECS or EC2. Since this package has no dependencies on AWS, it may also be used on any other cloud provider as well.
Before I set out to solve this issue, there were other packages on NPM that accomplished a similar idea although they were convoluted, not maintained, or not configurable enough. Ultimately I wanted a lightweight, simple solution that would be extremely easy to plug into several projects at work. I was able to create Lambda Log as a solution while only having a single dependency and a fairly small code-base.
Over time, Lambda Log has evolved from a simple JSON logger to something that is more customizable and feature-rich. Some of the main features are:
- Ability to log in JSON format in different log levels.
- Include metadata and tags for all logs.
- Extendable by wrapping or extending the LambdaLog class.
- Emits logs as an event to allow third-party integrations.
- Automatically included stacktraces from Error and Error-like objects.
- Pretty-printing of JSON object in dev mode.
- Small footprint.