Skip to content

Commit 0d553cf

Browse files
Add ability to suppress messages from stacktrace (#1104)
* Add ability to suppress messages from stacktrace Update README.md * Rename ShortenedThrowableConverter.SANITIZE to OMIT_THROWABLE_MESSAGE add unit test * Use a BasicMarkerFactory to construct OMIT_THROWABLE_MESSAGE marker --------- Co-authored-by: Patrick Barry <[email protected]>
1 parent c9318cd commit 0d553cf

File tree

3 files changed

+167
-84
lines changed

3 files changed

+167
-84
lines changed

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ The structure of the output, and the data it contains, is fully configurable.
6666
* [Omit Common Frames](#omit-common-frames)
6767
* [Truncate after Regex](#truncate-after-regex)
6868
* [Exclude Frames per Regex](#exclude-frames-per-regex)
69+
* [Omit Throwable Messages](#omit-throwable-messages)
6970
* [Maximum Depth per Throwable](#maximum-depth-per-throwable)
70-
* [Maximum Trace Size (bytes)](#maximum-trace-size)
71+
* [Maximum Trace Size (bytes)](#maximum-trace-size-bytes)
7172
* [Classname Shortening](#classname-shortening)
7273
* [Custom Line Separator](#custom-line-separator)
7374
* [Root Cause First](#root-cause-first)
@@ -2124,6 +2125,47 @@ Alternatively, multiple exclusion patterns can be specified at once using the `<
21242125
Using the `<exclusions>` configuration option can be useful when using an environment variable to specify the actual patterns at deployment time.
21252126

21262127

2128+
### Omit Throwable Messages
2129+
2130+
To omit throwable messages from stacktraces, add the `ShortenedThrowableConverter.OMIT_THROWABLE_MESSAGE` marker
2131+
to log statements.
2132+
2133+
Consider the following stacktrace (without omitting messages):
2134+
2135+
```
2136+
Exception in thread "main" com.myproject.module.MyProjectFooBarException: Customer ssn of 12345678 was not registered
2137+
at com.myproject.module.MyProject.anotherMethod(MyProject.java:19)
2138+
at com.myproject.module.MyProject.someMethod(MyProject.java:12)
2139+
at com.myproject.module.MyProject.main(MyProject.java:8)
2140+
Caused by: java.lang.ArithmeticException: Could not generate userId for Customer with phone number 111-111-1111
2141+
at org.apache.commons.lang3.math.Fraction.getFraction(Fraction.java:143)
2142+
at com.myproject.module.MyProject.anotherMethod(MyProject.java:17)
2143+
... 2 more
2144+
```
2145+
2146+
If the `ShortenedThrowableConverter.OMIT_THROWABLE_MESSAGE` marker is used when logging the above throwable,
2147+
then the `ShortenedThrowableConverter` will omit all messages in the stacktrace.
2148+
2149+
For example, the following code:
2150+
2151+
```java
2152+
logger.error(OMIT_THROWABLE_MESSAGE, "An exception was thrown but I want to make sure no customer data is shown in stacktrace", e);
2153+
```
2154+
2155+
will produce:
2156+
2157+
```
2158+
Exception in thread "main" com.myproject.module.MyProjectFooBarException:
2159+
at com.myproject.module.MyProject.anotherMethod(MyProject.java:19)
2160+
at com.myproject.module.MyProject.someMethod(MyProject.java:12)
2161+
at com.myproject.module.MyProject.main(MyProject.java:8)
2162+
Caused by: java.lang.ArithmeticException:
2163+
at org.apache.commons.lang3.math.Fraction.getFraction(Fraction.java:143)
2164+
at com.myproject.module.MyProject.anotherMethod(MyProject.java:17)
2165+
... 2 more
2166+
```
2167+
2168+
This enables devs to still see the type of exception thrown and where it occurred, **without** exposing sensitive data.
21272169

21282170
### Maximum Depth per Throwable
21292171

@@ -2843,7 +2885,7 @@ The provider name is the xml element name to use when configuring. Each provider
28432885

28442886

28452887

2846-
### Providers for AccessEvents
2888+
### Providers for AccessEvents
28472889

28482890
The [common providers mentioned above](#providers-common-to-loggingevents-and-accessevents), and the providers listed in the table below, are available for _AccessEvents_.
28492891
The provider name is the xml element name to use when configuring. Each provider's configuration properties are shown, with default configuration values in parenthesis.

0 commit comments

Comments
 (0)