Description
Key information
- RFC PR:
- Related issue(s), if known:
- Area: Logger
- Meet tenets: Yes
Summary
Switch to logback GitHub repository, SLF4J and logstash as logging framework used by the Logging module.
Motivation
Currently the Lambda Powertools are using log4j2 as logging framework. Log4j2 is a very popular and widely used logging library in the Java ecosystem. It offers a lot of features that are most likely not required by most Lambda functions. One of these features (JNDI support) has gained a lot of popularity through CVE-2021-44228.
Another popular logging framework that derived from log4j1 is [logback]((https://logback.qos.ch). When using logbook it's also required to use SLF4J as an abstraction layer. For example logback is the default logging framework used by Spring Boot. It has a smaller jar-artefact footprint than log4j2.
logstash is another library that adds JSON formatting and structured logging to logback.
This would allow applications to add structured logging in a clean and convenient way without adding and removing additional keys explicitly (see proposal for an example). This is important because it reduces boilerplate code and the business logic gets more visibility.
Proposal
Replace the current usage of log4j2 with logback, SLF4J and also add logstash.
The interface of the Logging module would not have to change much. However, the configuration of the layout has to be changed to use logback and logstash.
As stated in the motivation section the usage of logstash would allow for clean implementation when using structured logging.
For example
LoggingUtils.appendKey("foo", "bar");
log.info("Hello World!")
LoggingUtils.removeKey("foo");
would become
log.info("Hello World! {}", kv("foo", "bar"));
Beside this common use-case logstash offers other convenient methods to generate these structured arguments. Structured Logging with Structured Arguments for more details
Dependency analysis
License
Logback
Dual license model:
Eclipse Public License v1.0
GNU Lesser General Public License version 2.1
SLF4J
MIT license
Logstash
Apache 2
Releases
New releases on a regular basis
Community
PR activity on the project is moderate on both projects
Project maintainer take part in active community discussions for logback on GitHub
Jira for issue tracking and logstash on GitHub
Size of library and dependencies (current versions as of 2022-10-29)
Jackson dependency is already part of Lambda Powertools for Java and required for both approaches.
logback + SLF4J + Logstash
- slf4j-api-2.0.3.jar, 61.41 kB
- logback-classic-1.4.4.jar, 266.09 kB
- logback-core-1.4.4.jar, 576.91 kB
- logstash-logback-encoder-7.2.jar, 408 kB
Sum: ~1.3 MB
Log4J2
- log4j-api-2.19.0.jar, 317.57 kB
- log4j-core-2.19.0.jar, 1.86 MB
Sum: ~2.2 MB
Please note that Lambda Powertools requires more Dependencies like Jackson for JSON layout serialization.
Drawbacks
Changing the logging framework would mean a breaking change for existing applications and also effect other modules of the Lambda Powertools for Java.
It may also be possible that organizations don't want/allow using logback or prefer log4j over logback for other reasons. This could be mitigated by SLF4J which offers a unified API to use either logback or log4j2. This would still be a breaking change for existing applications.
Rationale and alternatives
Unresolved questions
- Does logstash allow to define a layout that is similar to
LambdaJsonLayout.json
Metadata
Metadata
Assignees
Labels
Type
Projects
Status