Skip to content

Commit ec4ae2f

Browse files
Remove dynamic log level after request
Change-Id: Ic59696b197392ecabe29665d822d12c838cdbeed
1 parent 126ebf8 commit ec4ae2f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/dynlog/DynamicLogLevelProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ public void copyDynamicLogLevelToMDC(HttpServletRequest httpRequest) {
5151
}
5252
}
5353
}
54+
55+
public void removeDynamicLogLevelFromMDC() {
56+
MDC.remove(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY);
57+
}
5458
}

cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/RequestLoggingFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ private void doFilterRequest(HttpServletRequest httpRequest, HttpServletResponse
149149
*/
150150
} finally {
151151
rr.close();
152+
153+
if (dynamicLogLevelProcessor != null) {
154+
dynamicLogLevelProcessor.removeDynamicLogLevelFromMDC();
155+
}
152156
}
153157
}
154158

cf-java-logging-support-servlet/src/test/java/com/sap/hcp/cf/logging/servlet/dynlog/DynamicLogLevelProcessorTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ public void testCopyDynamicLogLevelToMDC() throws Exception {
5555
processor.copyDynamicLogLevelToMDC(httpRequest);
5656
assertEquals("TRACE", MDC.get(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY));
5757
}
58+
59+
@Test
60+
public void testDeleteDynamicLogLevelFromMDC() throws Exception {
61+
processor.copyDynamicLogLevelToMDC(httpRequest);
62+
processor.removeDynamicLogLevelFromMDC();
63+
assertEquals(null, MDC.get(DynamicLogLevelHelper.MDC_DYNAMIC_LOG_LEVEL_KEY));
64+
}
5865
}

0 commit comments

Comments
 (0)