Skip to content

Commit

Permalink
#37 - fix overriding log4j version + mark custom loggers in view
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehertwig committed Apr 8, 2018
1 parent ba0f899 commit 223fc2a
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 36 deletions.
13 changes: 12 additions & 1 deletion admin-tools-demo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<packaging>jar</packaging>

<properties>
<log4j2.version>2.9.1</log4j2.version>
<log4j2.version>2.11.0</log4j2.version>
<quartz-version>2.3.0</quartz-version>
</properties>

Expand Down Expand Up @@ -134,6 +134,17 @@
<artifactId>log4j-web</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
53 changes: 28 additions & 25 deletions admin-tools-demo-core/src/main/java/de/chandre/admintool/Beans.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
23 changes: 22 additions & 1 deletion admin-tools-demo-jar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<properties>
<jminix.version>1.2.0</jminix.version>
<log4j2.version>2.6.2</log4j2.version>
<log4j2.version>2.11.0</log4j2.version>
</properties>

<dependencies>
Expand All @@ -42,6 +42,27 @@
<artifactId>flyway-core</artifactId>
<version>4.1.0</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

</dependencies>

Expand Down
23 changes: 22 additions & 1 deletion admin-tools-demo-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<properties>
<jminix.version>1.2.0</jminix.version>
<log4j2.version>2.6.2</log4j2.version>
<log4j2.version>2.11.0</log4j2.version>
</properties>

<dependencies>
Expand All @@ -43,6 +43,27 @@
<artifactId>flyway-core</artifactId>
<version>4.1.0</version><!--$NO-MVN-MAN-VER$-->
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>

</dependencies>

Expand Down
5 changes: 0 additions & 5 deletions admin-tools-log4j2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<version>${log4j.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<optional>true</optional>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ <h3 class="box-title">
<td class="logname" th:with="appenders = ${@adminToolLog4j2Util.getAppendersForLogger(logger.getName())}"
th:title="'AppenderRefs: ' + ${appenders}"
th:attr="data-appenders=${appenders}"
th:text="${#strings.defaultString(logger.getName(),'ROOT')}"></td>
th:inline="text">[[${#strings.defaultString(logger.getName(),'ROOT')}]]
<span th:if="${@adminToolLog4j2Util.isCustom(logger.getName())}" class="label label-default" th:text="Custom"></span>
</td>
<td th:text="${logger.getLevel()}"
th:class="'loglevel text-center ' + ${@adminToolLog4j2Util.getLoggerLevelCss('bg', logger.getLevel())}"></td>
<td class="logaction">
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@
<skip.unit.tests>false</skip.unit.tests>
<jacoco-maven-plugin.version>0.7.9</jacoco-maven-plugin.version>

<commons-lang.version>3.6</commons-lang.version>
<commons-lang.version>3.7</commons-lang.version>
<commons-collections.version>4.1</commons-collections.version>
<commons-io.version>2.5</commons-io.version>
<commons-io.version>2.6</commons-io.version>
<commons-logging.version>1.2</commons-logging.version>

<org.json.version>20151123</org.json.version>
Expand Down

0 comments on commit 223fc2a

Please sign in to comment.