Skip to content

Commit a1d9b36

Browse files
committed
fix
1 parent 39cec0a commit a1d9b36

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public class JavaUtilLoggingWithExceptionServlet extends HttpServlet {
1616
private static final Logger logger = Logger.getLogger("smoketestapp");
1717

1818
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
19+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
20+
logger.log(Level.SEVERE, "This is an exception!", e);
21+
}
22+
23+
private static boolean testNullMessage(HttpServletRequest request) {
1924
String testNullMessage = request.getParameter("test-null-message");
20-
if ("true".equalsIgnoreCase(testNullMessage)) {
21-
logger.log(Level.SEVERE, "This is an exception!", new Exception());
22-
} else {
23-
logger.log(Level.SEVERE, "This is an exception!", new Exception("Fake Exception"));
24-
}
25+
return "true".equalsIgnoreCase(testNullMessage);
2526
}
2627
}

smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public class Log4j1WithExceptionServlet extends HttpServlet {
3535
@Override
3636
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
3737
MDC.put("MDC key", "MDC value");
38-
String testNullMessage = request.getParameter("test-null-message");
39-
if ("true".equalsIgnoreCase(testNullMessage)) {
40-
logger.error("This is an exception!", new Exception());
41-
} else {
42-
logger.error("This is an exception!", new Exception("Fake Exception"));
43-
}
38+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
39+
logger.error("This is an exception!", e);
4440
MDC.remove("MDC key");
4541
}
42+
43+
private static boolean testNullMessage(HttpServletRequest request) {
44+
String testNullMessage = request.getParameter("test-null-message");
45+
return "true".equalsIgnoreCase(testNullMessage);
46+
}
4647
}

smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ public class Log4j2WithExceptionServlet extends HttpServlet {
1818

1919
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2020
ThreadContext.put("MDC key", "MDC value");
21-
String testNullMessage = request.getParameter("test-null-message");
22-
if ("true".equalsIgnoreCase(testNullMessage)) {
23-
logger.error("This is an exception!", new Exception());
24-
} else {
25-
logger.error("This is an exception!", new Exception("Fake Exception"));
26-
}
21+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
22+
logger.error("This is an exception!", e);
2723
ThreadContext.remove("MDC key");
2824
}
25+
26+
private static boolean testNullMessage(HttpServletRequest request) {
27+
String testNullMessage = request.getParameter("test-null-message");
28+
return "true".equalsIgnoreCase(testNullMessage);
29+
}
2930
}

smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ public class LogbackWithExceptionServlet extends HttpServlet {
1818

1919
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2020
MDC.put("MDC key", "MDC value");
21-
String testNullMessage = request.getParameter("test-null-message");
22-
if ("true".equalsIgnoreCase(testNullMessage)) {
23-
logger.error("This is an exception!", new Exception());
24-
} else {
25-
logger.error("This is an exception!", new Exception("Fake Exception"));
26-
}
21+
Exception e = testNullMessage(request) ? new Exception() : new Exception("Fake Exception");
22+
logger.error("This is an exception!", e);
2723
MDC.remove("MDC key");
2824
}
25+
26+
private static boolean testNullMessage(HttpServletRequest request) {
27+
String testNullMessage = request.getParameter("test-null-message");
28+
return "true".equalsIgnoreCase(testNullMessage);
29+
}
2930
}

smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void testWithException(boolean testNullMessage) throws Exception {
162162
"ClassName",
163163
"com.microsoft.applicationinsights.smoketestapp.LogbackWithExceptionServlet")
164164
.containsEntry("MethodName", "doGet")
165-
.containsEntry("LineNumber", "25")
165+
.containsEntry("LineNumber", "22")
166166
.hasSize(9);
167167
} else {
168168
assertThat(ed.getProperties()).hasSize(5);

0 commit comments

Comments
 (0)