Hello,
While logging works nicely when the hikari(2.4.6) jar is bundled in the application's war, when we move it to Tomcat(8.0.32) /lib directory, hikari stops logging. I have followed a similar issue here (809) where there was some guidance in achieving this, but I cannot get it to work. For our application it is very crucial to monitor the pool:
2017-02-01 12:27:17.274 DEBUG 26240 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
so we need a way to get this info in catalina.out
My tomcat setup is as following:
/lib directory:

and my logging.properties:
````
#
#
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
1catalina.org.apache.juli.AsyncFileHandler.level = FINEST
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
com.zaxxer.hikari.level = FINEST
com.zaxxer.hikari.handlers = 1catalina.org.apache.juli.AsyncFileHandler
````
Please provide me some info on how to get this working.
Thank you very much
Panos
Maybe someone else can jump in here to help.
Posted the same question in StackOverflow in case someone can help. thanks
@pleft I hope you got this working. It does work, because other users have done it. You might search for some blogs or other stackoverflow answers regarding it.
Hi, unfortunately as I have stated in my first post, any research I did, lead me to the configuration I posted, however it does not work. So no, it still doesn't work. I would appreciate if you could point me the stackoverflow answers or blogs dealing the exact same problem.
I do not understand why you closed this question? It is still unanswered here!
Hi again,
Thanks. Already did what this stackoverflow link suggests, it was one of the first links I read trying to solve my problem. Unfortunately in my case it doesn't work. Moreover you point me to a stackoverflow question with 0 votes, one answer with also 0 votes and not even accepted by the question poster.
Could somebody please take a look at my setup and spend sometime to spot what is wrong? I have all info posted in my first post here, I think I am pretty explanatory and comprehensive, if required I can post more info. I would appreciate an answer in the same level.
A correct and thorough answer here would also lead as a guide for anyone has this kind of problem (and there are a lot of them).
Thank you.
@pleft You can try on the Google Group, you might find another user with a similar setup. This is not exactly rocket science in terms of debugging. If it works when the jars are in the war, but not without, it is a simple classloading issue. Setting a breakpoint in HikariCP where the logger is acquired, and then inspecting the logger's parent and classloading chain should easily reveal whether that logger and the Tomcat root logger share the same classloader; if not it should be apparent where the logger given to HikariCP is sourced from.
Lastly, make sure that there are no temporary HikariCP jars anywhere except the Tomcat lib directory. Having deploying once with the jars in the WAR, Tomcat is likely to have copied the jars to a temporary deployment directory. Neither HikariCP's jars nor any of the slf4j related jars should be anywhere except the lib directory.
Solution:
First of all, tomcat server internal logging must be changed from Apache Commons Logging to log4j. The procedure to do this is described here. Assuming having read the links above and downloaded the aforementioned jars from the extras bundle (tomcat-juli-adapters.jar, tomcat-juli.jar) and log4j.jar.
log4j.properties file should be placed to tomcat/lib directory.logging.properties file from tomcat/conf directory, so tomcat doesn't pick it up during startup.tomcat/lib directory: log4j-1.2.17.jar, tomcat-juli-adapters.jartomcat/bin directory: tomcat-juli.jarAfter the above steps, tomcat should now log using log4j.
To enable HikariCP logging do the following:
log4j.properties file and at the end add the following line:log4j.logger.com.zaxxer.hikari = DEBUGMy log4j.properties file:
log4j.rootLogger = INFO, CATALINA
# Define all the appenders
log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File = ${catalina.base}/logs/catalina
log4j.appender.CATALINA.Append = true
log4j.appender.CATALINA.Encoding = UTF-8
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost
log4j.appender.LOCALHOST.Append = true
log4j.appender.LOCALHOST.Encoding = UTF-8
log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File = ${catalina.base}/logs/manager
log4j.appender.MANAGER.Append = true
log4j.appender.MANAGER.Encoding = UTF-8
log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager
log4j.appender.HOST-MANAGER.Append = true
log4j.appender.HOST-MANAGER.Encoding = UTF-8
log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding = UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
# Configure which loggers log to which appenders
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
INFO, HOST-MANAGER
log4j.logger.com.zaxxer.hikari = DEBUG
@pleft Thanks for the follow-up! This will surely help other users in the future.
@pleft I am not able to get the hikaricp debug logs. I exactly followed the above steps. Log4j is properly configured. But hikari is not throwing any logs. My tomcat version 8.5.31. Hikaricp vesion is 2.7.9.
I am the following issue #1282 . So I am trying to debug
Most helpful comment
Solution:
First of all, tomcat server internal logging must be changed from Apache Commons Logging to log4j. The procedure to do this is described here. Assuming having read the links above and downloaded the aforementioned jars from the
extrasbundle (tomcat-juli-adapters.jar,tomcat-juli.jar) andlog4j.jar.log4j.propertiesfile should be placed totomcat/libdirectory.logging.propertiesfile fromtomcat/confdirectory, sotomcatdoesn't pick it up during startup.tomcat/libdirectory:log4j-1.2.17.jar,tomcat-juli-adapters.jartomcat/bindirectory:tomcat-juli.jarAfter the above steps,
tomcatshould now log usinglog4j.To enable
HikariCPlogging do the following:log4j.propertiesfile and at the end add the following line:log4j.logger.com.zaxxer.hikari = DEBUGMy
log4j.propertiesfile: