diff --git a/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutIntegrationTest.java b/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutIntegrationTest.java
index 06962c1ea1..f012769710 100644
--- a/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutIntegrationTest.java
+++ b/logging-modules/logback/src/test/java/com/baeldung/logback/JSONLayoutIntegrationTest.java
@@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class JSONLayoutIntegrationTest {
private static Logger logger;
+ private static Logger jsonlogger;
private ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
private PrintStream ps = new PrintStream(consoleOutput);
@@ -23,16 +24,24 @@ public class JSONLayoutIntegrationTest {
public void setUp() {
// Redirect console output to our stream
System.setOut(ps);
- logger = LoggerFactory.getLogger("jsonLogger");
}
@Test
- public void whenLogLayoutInJSON_thenOutputIsCorrectJSON() {
+ public void givenJsonLayout_whenLogInJSON_thenOutputIsCorrectJSON() {
+ logger = LoggerFactory.getLogger("jsonLogger");
logger.debug("Debug message");
String currentLog = consoleOutput.toString();
assertTrue(!currentLog.isEmpty() && isValidJSON(currentLog));
}
+ @Test
+ public void givenJsonEncoder_whenLogInJSON_thenOutputIsCorrectJSON() {
+ jsonlogger = LoggerFactory.getLogger("jsonEncoderLogger");
+ jsonlogger.debug("Debug message");
+ String currentLog = consoleOutput.toString();
+ assertTrue(!currentLog.isEmpty() && isValidJSON(currentLog));
+ }
+
public static boolean isValidJSON(String jsonInString) {
try {
final ObjectMapper mapper = new ObjectMapper();
diff --git a/logging-modules/logback/src/test/resources/logback-test.xml b/logging-modules/logback/src/test/resources/logback-test.xml
index 89c0124738..24082a673d 100644
--- a/logging-modules/logback/src/test/resources/logback-test.xml
+++ b/logging-modules/logback/src/test/resources/logback-test.xml
@@ -19,10 +19,18 @@
+
+
+
+
+
+
+
+