From 223fc2abaa9d68c2eb0b635fc84a2bf3a6e873da Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 8 Apr 2018 17:53:13 +0200 Subject: [PATCH] #37 - fix overriding log4j version + mark custom loggers in view --- admin-tools-demo-core/pom.xml | 13 ++++- .../main/java/de/chandre/admintool/Beans.java | 53 ++++++++++--------- admin-tools-demo-jar/pom.xml | 23 +++++++- admin-tools-demo-war/pom.xml | 23 +++++++- admin-tools-log4j2/pom.xml | 5 -- .../templates/admintool/content/log4j2.html | 4 +- pom.xml | 4 +- 7 files changed, 89 insertions(+), 36 deletions(-) diff --git a/admin-tools-demo-core/pom.xml b/admin-tools-demo-core/pom.xml index 8fcfc80..bd4c722 100644 --- a/admin-tools-demo-core/pom.xml +++ b/admin-tools-demo-core/pom.xml @@ -18,7 +18,7 @@ jar - 2.9.1 + 2.11.0 2.3.0 @@ -134,6 +134,17 @@ log4j-web ${log4j2.version} + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j2.version} + + + + org.slf4j + log4j-over-slf4j + + org.springframework.boot spring-boot-configuration-processor diff --git a/admin-tools-demo-core/src/main/java/de/chandre/admintool/Beans.java b/admin-tools-demo-core/src/main/java/de/chandre/admintool/Beans.java index 83d0462..22d3fbb 100644 --- a/admin-tools-demo-core/src/main/java/de/chandre/admintool/Beans.java +++ b/admin-tools-demo-core/src/main/java/de/chandre/admintool/Beans.java @@ -15,8 +15,9 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.db.ColumnMapping; +import org.apache.logging.log4j.core.appender.db.jdbc.AbstractConnectionSource; import org.apache.logging.log4j.core.appender.db.jdbc.ColumnConfig; -import org.apache.logging.log4j.core.appender.db.jdbc.ConnectionSource; import org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.LoggerConfig; @@ -123,32 +124,33 @@ public Appender datasourceAppender(DataSource dataSource, AdminToolLog4j2Util lo final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); final Configuration config = ctx.getConfiguration(); -// ColumnConfig[] cc = { -// ColumnConfig.newBuilder().setConfiguration(config).setName("DATE").setEventTimestamp(true).build(), -// ColumnConfig.newBuilder().setConfiguration(config).setName("LEVEL").setPattern("%level").build(), -// ColumnConfig.newBuilder().setConfiguration(config).setName("LOGGER").setPattern("%logger").build(), -// ColumnConfig.newBuilder().setConfiguration(config).setName("MESSAGE").setPattern("%message").setClob(true).build(), -// ColumnConfig.newBuilder().setConfiguration(config).setName("EXCEPTION").setPattern("%ex{full}").setClob(true).build() -// }; -// -// Appender appender = JdbcAppender.newBuilder() -// .setBufferSize(0) -// .setColumnConfigs(cc) -// .setConnectionSource(new Connect(dataSource)) -// .setTableName("LOGGING") -// .withName("databaseAppender") -// .withIgnoreExceptions(false) -// .build(); - ColumnConfig[] cc = { - ColumnConfig.createColumnConfig(config, "DATE", null, null, "true", null, null), - ColumnConfig.createColumnConfig(config, "LEVEL", "%level", null, null, null, null), - ColumnConfig.createColumnConfig(config, "LOGGER", "%logger", null, null, null, null), - ColumnConfig.createColumnConfig(config, "MESSAGE", "%message", null, null, null, "true"), - ColumnConfig.createColumnConfig(config, "EXCEPTION", "%ex{full}", null, null, null, "true"), + ColumnConfig.newBuilder().setConfiguration(config).setName("DATE").setEventTimestamp(true).build(), + ColumnConfig.newBuilder().setConfiguration(config).setName("LEVEL").setPattern("%level").build(), + ColumnConfig.newBuilder().setConfiguration(config).setName("LOGGER").setPattern("%logger").build(), + ColumnConfig.newBuilder().setConfiguration(config).setName("MESSAGE").setPattern("%message").setClob(true).build(), + ColumnConfig.newBuilder().setConfiguration(config).setName("EXCEPTION").setPattern("%ex{full}").setClob(true).build() }; - Appender appender = JdbcAppender.createAppender("databaseAppender", "false", null, new Connect(dataSource), "0", "LOGGING", cc); + Appender appender = JdbcAppender.newBuilder() + .setBufferSize(0) + .setColumnConfigs(cc) + .setColumnMappings(new ColumnMapping[]{}) + .setConnectionSource(new Connect(dataSource)) + .setTableName("LOGGING") + .withName("databaseAppender") + .withIgnoreExceptions(false) + .build(); + +// ColumnConfig[] cc = { +// ColumnConfig.createColumnConfig(config, "DATE", null, null, "true", null, null), +// ColumnConfig.createColumnConfig(config, "LEVEL", "%level", null, null, null, null), +// ColumnConfig.createColumnConfig(config, "LOGGER", "%logger", null, null, null, null), +// ColumnConfig.createColumnConfig(config, "MESSAGE", "%message", null, null, null, "true"), +// ColumnConfig.createColumnConfig(config, "EXCEPTION", "%ex{full}", null, null, null, "true"), +// }; +// Appender appender = JdbcAppender.createAppender("databaseAppender", "false", null, new Connect(dataSource), "0", "LOGGING", cc); + appender.start(); config.addAppender(appender); LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); @@ -170,11 +172,12 @@ public Appender datasourceAppender(DataSource dataSource, AdminToolLog4j2Util lo } // inner class - class Connect implements ConnectionSource { + class Connect extends AbstractConnectionSource { private DataSource dsource; public Connect(DataSource dsource) { this.dsource = dsource; + setState(State.STARTED); } @Override diff --git a/admin-tools-demo-jar/pom.xml b/admin-tools-demo-jar/pom.xml index 51240c6..9805f74 100644 --- a/admin-tools-demo-jar/pom.xml +++ b/admin-tools-demo-jar/pom.xml @@ -19,7 +19,7 @@ 1.2.0 - 2.6.2 + 2.11.0 @@ -42,6 +42,27 @@ flyway-core 4.1.0 + + + org.apache.logging.log4j + log4j-api + ${log4j2.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + + + org.apache.logging.log4j + log4j-web + ${log4j2.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j2.version} + diff --git a/admin-tools-demo-war/pom.xml b/admin-tools-demo-war/pom.xml index 2300c57..04ac8c9 100644 --- a/admin-tools-demo-war/pom.xml +++ b/admin-tools-demo-war/pom.xml @@ -19,7 +19,7 @@ 1.2.0 - 2.6.2 + 2.11.0 @@ -43,6 +43,27 @@ flyway-core 4.1.0 + + + org.apache.logging.log4j + log4j-api + ${log4j2.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + + + org.apache.logging.log4j + log4j-web + ${log4j2.version} + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j2.version} + diff --git a/admin-tools-log4j2/pom.xml b/admin-tools-log4j2/pom.xml index a8445f7..cff5484 100644 --- a/admin-tools-log4j2/pom.xml +++ b/admin-tools-log4j2/pom.xml @@ -46,11 +46,6 @@ ${log4j.version} true - - org.apache.logging.log4j - log4j-slf4j-impl - true - diff --git a/admin-tools-log4j2/src/main/resources/templates/admintool/content/log4j2.html b/admin-tools-log4j2/src/main/resources/templates/admintool/content/log4j2.html index 7dbe0b2..a9f782e 100644 --- a/admin-tools-log4j2/src/main/resources/templates/admintool/content/log4j2.html +++ b/admin-tools-log4j2/src/main/resources/templates/admintool/content/log4j2.html @@ -48,7 +48,9 @@

+ th:inline="text">[[${#strings.defaultString(logger.getName(),'ROOT')}]] + + diff --git a/pom.xml b/pom.xml index 05e29c0..1a84f96 100644 --- a/pom.xml +++ b/pom.xml @@ -200,9 +200,9 @@ false 0.7.9 - 3.6 + 3.7 4.1 - 2.5 + 2.6 1.2 20151123