Skip to content

Commit

Permalink
fix stubbing error
Browse files Browse the repository at this point in the history
  • Loading branch information
kayman-mk committed Mar 22, 2024
1 parent 3f13cfe commit afe62fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- First line should be an H1: Badges on top please! -->
<!-- markdownlint-disable first-line-h1 -->
[![Actions](https://github.com/Hapag-Lloyd/log4j2-filtered-stacktrace-plugin/workflows/semantic-release/badge.svg)](https://github.com/Hapag-Lloyd/log4j2-filtered-stacktrace-plugin/actions)
[![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)
<!-- markdownlint-enable first-line-h1 -->

Expand All @@ -20,7 +20,7 @@ We replaced the main logic completely.
Adding the filter to the logging configuration with `<EventTemplateAdditionalField key="error" format="JSON" value='{"$resolver": "filteredStacktraceException"}'/>`
produces the following Json object in the log stream:

<!-- no line breaks in Json please -->
<!-- no line breaks in Json please, we are fine with long lines here -->
<!-- markdownlint-disable line-length -->
```json
"error": {
Expand All @@ -41,24 +41,26 @@ produces the following Json object in the log stream:
Include the following artifact to your project which contains the `log4j2.xml` configuration file. Make sure to use the newest version.

```xml
<!-- pom.xml -->
<dependency>
<groupId>com.hlag.logging</groupId>
<artifactId>log4j2-stacktrace-filter</artifactId>
<!-- make sure to use the newest version -->
<version>1.0.0</version>
<version>1.3.0</version>
</dependency>
```

## Log4j2 Configuration

<!-- no line breaks in Json please -->
<!-- no line breaks in Json please, we are fine with long lines here -->
<!-- markdownlint-disable line-length -->
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- log4j2.xml -->
<Configuration status="INFO">

<Appenders>
<Console name="console-datadog" target="SYSTEM_OUT">
<Console name="console" target="SYSTEM_OUT">
<JsonTemplateLayout eventTemplateUri="classpath:JsonLayout.json" maxStringLength="32768" stackTraceEnabled="false">
<EventTemplateAdditionalField key="error" format="JSON"
value='{"$resolver": "filteredStacktraceException"}, "additionalPackagesToIgnore": ["com.hlag.logging.log4j2."]}' />
Expand All @@ -79,3 +81,10 @@ Include the following artifact to your project which contains the `log4j2.xml` c

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 add packages which should not be ignored. This is useful if you want to ignore all packages except a few. The
built-in list is ignored in this case as well as `additionalPackagesToIgnore`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -38,6 +39,7 @@ void setUp() {
Mockito.lenient().when(mockedEventResolverContext.getMaxStringByteCount()).thenReturn(10000);

Mockito.when(mockedConfig.getList("additionalPackagesToIgnore", String.class)).thenReturn(PACKAGE_TO_REMOVE_FROM_STACKTRACE);
Mockito.when(mockedConfig.getList("whitelistPackages", String.class)).thenReturn(new ArrayList<>());

jsonWriter = JsonWriter.newBuilder().setMaxStringLength(10000).setTruncatedStringSuffix("...").build();

Expand Down

0 comments on commit afe62fb

Please sign in to comment.