BAEL-41 - Log4j 2 appenders, layout, filters

This commit is contained in:
slavisa-baeldung 2017-02-20 20:03:32 +01:00
parent 30fccad5f4
commit 99dbc3efd1
2 changed files with 5 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.ResultSet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
@ -25,7 +26,7 @@ public class CustomLoggingTest {
public static void setup() throws Exception {
Connection connection = ConnectionFactory.getConnection();
connection.createStatement()
.execute("CREATE TABLE logs(" + "when TIMESTAMP," + "logger VARCHAR(255)," + "level VARCHAR(255)," + "message VARCHAR(4096)," + "throwable TEXT)");
.execute("CREATE TABLE logs(" + "when TIMESTAMP," + "logger VARCHAR(255)," + "level VARCHAR(255)," + "message VARCHAR(4096)," + "throwable TEXT)");
connection.commit();
}
@ -76,7 +77,7 @@ public class CustomLoggingTest {
logger.info("This is async JSON message #{} at INFO level.", count);
}
long logEventsCount = Files.lines(Paths.get("target/logfile.json"))
.count();
.count();
assertTrue(logEventsCount > 0 && logEventsCount <= count);
}
@ -101,7 +102,7 @@ public class CustomLoggingTest {
}
Connection connection = ConnectionFactory.getConnection();
ResultSet resultSet = connection.createStatement()
.executeQuery("SELECT COUNT(*) AS ROW_COUNT FROM logs");
.executeQuery("SELECT COUNT(*) AS ROW_COUNT FROM logs");
int logCount = 0;
if (resultSet.next()) {
logCount = resultSet.getInt("ROW_COUNT");

View File

@ -2,6 +2,7 @@ package com.baeldung.logging.log4j2.tests.jdbc;
import org.apache.commons.dbcp2.BasicDataSource;
import org.h2.Driver;
import java.sql.Connection;
import java.sql.SQLException;