You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
@@ -2124,6 +2125,47 @@ Alternatively, multiple exclusion patterns can be specified at once using the `<
2124
2125
Using the `<exclusions>` configuration option can be useful when using an environment variable to specify the actual patterns at deployment time.
2125
2126
2126
2127
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.
2127
2169
2128
2170
### Maximum Depth per Throwable
2129
2171
@@ -2843,7 +2885,7 @@ The provider name is the xml element name to use when configuring. Each provider
2843
2885
2844
2886
2845
2887
2846
-
### Providers for AccessEvents
2888
+
### Providers for AccessEvents
2847
2889
2848
2890
The [common providers mentioned above](#providers-common-to-loggingevents-and-accessevents), and the providers listed in the table below, are available for _AccessEvents_.
2849
2891
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