I have a scenario where I need to put the value in sl4j.MDC.put("Authorization",(bearer token)). As,it's a thread safe I need to pass it to downstream API in headers. But now the issue is the value is getting printed in my logs as well. Is there any way that I can setup my log4j.xml file to ignore the value "Authorization" to print.
Asked
Active
Viewed 260 times
1
-
Are you using Log4j 1.x or Log4j 2? – rgoers Jan 15 '20 at 18:59
-
I am using Log4j2 – abhishek chauhan Jan 16 '20 at 03:41
1 Answers
0
With Log4j2 ignoring specific ThreadContext values depends on the Layout you are using.
- PatternLayout - Use
%X{key1,key2}
to identity which keys you want to include - GelfLayout - Use the threadContextIncludes or threadContextExcludes to provide a list of keys you want included or excluded.
- RFC5424Layout - Use the mdcIncludes or mdcExcludes parameters to specify the list of keys to be included or excluded.
Other Layouts don't accept parameters to include or exclude specific attributes. If you are looking for an enhancement please create a Jira issue for Log4j 2.

rgoers
- 8,696
- 1
- 22
- 24