Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hapag-lloyd/log4j2-filtered-stacktrace-plugin
Plugin for Log4j2 to reduce noise in stacktraces.
https://github.com/hapag-lloyd/log4j2-filtered-stacktrace-plugin
filter java log4j2 logger logging plugin stacktrace
Last synced: about 7 hours ago
JSON representation
Plugin for Log4j2 to reduce noise in stacktraces.
- Host: GitHub
- URL: https://github.com/hapag-lloyd/log4j2-filtered-stacktrace-plugin
- Owner: Hapag-Lloyd
- License: apache-2.0
- Created: 2024-03-15T14:14:16.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-22T19:38:51.000Z (6 months ago)
- Last Synced: 2024-05-22T20:45:47.134Z (6 months ago)
- Topics: filter, java, log4j2, logger, logging, plugin, stacktrace
- Language: Java
- Homepage:
- Size: 264 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[![Actions](https://github.com/Hapag-Lloyd/log4j2-filtered-stacktrace-plugin/workflows/Release/badge.svg)](https://github.com/Hapag-Lloyd/log4j2-filtered-stacktrace-plugin/actions)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.hlag.logging/log4j2-stacktrace-filter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.hlag.logging/log4j2-stacktrace-filter-plugin)# Filter Stacktrace Plugin for Log4j2
This project contains a stacktrace filter for the Log4j2 logging system. It can be included in a [`JsonTemplateLayout`](https://logging.apache.org/log4j/2.x/manual/json-template-layout.html).
The plugin reduces the stacktrace by filtering classes which are not of any interest. It has a built-in list of packages to exclude
from the stacktrace. Additional packages can be configured in the `log4j2.xml` file. Find the full blown example below.This plugin was built on top of the work of the Apache Log4j team and takanuva15, who described the plugin in a
[Stackoverflow article](https://stackoverflow.com/questions/70614495/is-there-a-way-to-override-the-exceptionresolver-of-jsontemplatelayout-of-log4j2/77143208#77143208).
We replaced the main logic completely.# Output
Adding the filter to the logging configuration with ``
produces the following Json object in the log stream:```json
"error": {
"stack": "java.lang.RuntimeException: java.lang.ArithmeticException: / by zero\r\n\tat com.hlag.logging.log4j2.LoggerIntegrationTest.wrapException(LoggerIntegrationTest.java:21)\r\n\tat com.hlag.logging.log4j2.LoggerIntegrationTest.logException(LoggerIntegrationTest.java:11)\r\n\t[suppressed 70 lines]\r\ncaused by java.lang.ArithmeticException\r\n\tat com.hlag.logging.log4j2.LoggerIntegrationTest.throwArithmeticException(LoggerIntegrationTest.java:25)\r\n\tat com.hlag.logging.log4j2.LoggerIntegrationTest.wrapException(LoggerIntegrationTest.java:19)\r\n\tat com.hlag.logging.log4j2.LoggerIntegrationTest.logException(LoggerIntegrationTest.java:11)\r\n\t[suppressed 70 lines]",
"name": "java.lang.RuntimeException",
"message": "java.lang.ArithmeticException: / by zero",
"totalFilteredElements": 140
}
```140 elements have been removed from the stacktrace. Only those remain which are relevant for your application.
# Usage
## Maven Dependency
Include the following artifact to your project which contains the `log4j2.xml` configuration file. Make sure to use the newest version.
```xml
com.hlag.logging
log4j2-stacktrace-filter
1.3.0```
## Log4j2 Configuration
```xml
```
### additionalPackagesToIgnore
Use this parameter to add other packages to the built-in list. These packages are ignored too. Especially useful if you have to
include company internal frameworks, but you don't want to see them in the stacktrace.Makes no sense to specify `whitelistedPackages` in addition to this parameter.
### whitelistPackages
Use this parameter to define packages which should remain when filtering a stack trace. Every other package is removed from the
stacktrace. The built-in list of packages to filter as well as the `additionalPackagesToIgnore` parameter have no effect when
`whitelistPackages` exists.