Zixradoom Zixradoom - 1 year ago 191
Java Question

How to configure log4j2 to log for HikariCP

I have written a small Gradle project so that I can learn how to configure HikariCP and JDBC and Log4j2 all together in the same project. I have placed the below log4j2 config in the

directory in my project. When I execute the project using
gradle run
I get a warning about not configuring an appender for the

Would some one kindly tell me what i am doing wrong?


<?xml version="1.0" encoding="utf-8"?>
<Configuration status="WARN">
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Logger name="com.zaxxer.hikari.HikariConfig" level="trace">
<AppenderRef ref="Console"/>
<Root level="TRACE">
<AppenderRef ref="Console"/>


apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'application'

targetCompatibility = 1.8
sourceCompatibility = 1.8
version = ''
group = 'com.s2d'

mainClassName = "com.s2d.jdbctest.DemoJDBC"
applicationDefaultJvmArgs = ["-Djdbc.drivers=org.apache.derby.jdbc.EmbeddedDriver"]

task wrapper(type: Wrapper) {
gradleVersion = '1.4'

repositories {

dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.0.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.0.2'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.10'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.10'
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.3.7'
runtime group: 'org.apache.derby', name: 'derby', version: ''
testCompile group: 'junit', name: 'junit', version: '4.11'



task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir

artifacts {
archives sourcesJar
archives javadocJar

Execution output

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] run
[sts] -----------------------------------------------------
:compileJava UP-TO-DATE
20:27:11.247 [main] INFO com.s2d.jdbctest.DemoJDBC - Starting demo
log4j:WARN No appenders could be found for logger (com.zaxxer.hikari.HikariConfig).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Column Count: 1
Column 1 name: 1 type: DECIMAL
Inserted ID: 1005
20:27:12.350 [main] INFO com.s2d.jdbctest.DemoJDBC - Demo complete


Total time: 2.017 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 2 sec
[sts] -----------------------------------------------------

Answer Source

You're using slf4j-log4j12, which allows using slf4j to log messages with log4j 1.2. But your goal is to log messages using slf4j over log4j 2.0.2. So you need another binding library: https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html.

The Maven coordinates of this binding library are in the log4j2 documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download