HikariCP(2.4.6) in Tomcat(8.0.32) lib directory doesn't log

Created on 1 Feb 2017  路  10Comments  路  Source: brettwooldridge/HikariCP

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:

image

and my logging.properties:

````

Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the "License"); you may not use this file except in compliance with

the License. You may obtain a copy of the License at

#

http://www.apache.org/licenses/LICENSE-2.0

#

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

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

#

Handler specific properties.

Describes specific configuration info for Handlers.

#

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

#

Facility specific properties.

Provides extra control for each logger.

#

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

For example, set the org.apache.catalina.util.LifecycleBase logger to log

each component that extends LifecycleBase changing state:

org.apache.catalina.util.LifecycleBase.level = FINE

To see debug messages in TldLocationsCache, uncomment the following line:

org.apache.jasper.compiler.TldLocationsCache.level = FINE

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

question

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 extras bundle (tomcat-juli-adapters.jar, tomcat-juli.jar) and log4j.jar.

  • log4j.properties file should be placed to tomcat/lib directory.
  • Delete or rename logging.properties file from tomcat/conf directory, so tomcat doesn't pick it up during startup.
  • Copy the following jars to tomcat/lib directory: log4j-1.2.17.jar, tomcat-juli-adapters.jar
  • Copy and replace the following jar to tomcat/bin directory: tomcat-juli.jar

After the above steps, tomcat should now log using log4j.

To enable HikariCP logging do the following:

  • Edit log4j.properties file and at the end add the following line:
    log4j.logger.com.zaxxer.hikari = DEBUG
  • Make sure the following jars exist in tomcat/lib directory:

    • HikariCP-2.4.6.jar

    • jcl-over-slf4j-1.7.21.jar

    • slf4j-api-1.7.21.jar

    • slf4j-log4j12-1.7.21.jar

    • jul-to-slf4j-1.7.21.jar

My 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

All 10 comments

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.
  • Delete or rename logging.properties file from tomcat/conf directory, so tomcat doesn't pick it up during startup.
  • Copy the following jars to tomcat/lib directory: log4j-1.2.17.jar, tomcat-juli-adapters.jar
  • Copy and replace the following jar to tomcat/bin directory: tomcat-juli.jar

After the above steps, tomcat should now log using log4j.

To enable HikariCP logging do the following:

  • Edit log4j.properties file and at the end add the following line:
    log4j.logger.com.zaxxer.hikari = DEBUG
  • Make sure the following jars exist in tomcat/lib directory:

    • HikariCP-2.4.6.jar

    • jcl-over-slf4j-1.7.21.jar

    • slf4j-api-1.7.21.jar

    • slf4j-log4j12-1.7.21.jar

    • jul-to-slf4j-1.7.21.jar

My 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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ssinganamalla picture ssinganamalla  路  6Comments

scrumvisualize picture scrumvisualize  路  5Comments

TuomasKiviaho picture TuomasKiviaho  路  5Comments

mohsen picture mohsen  路  6Comments

dskorka picture dskorka  路  4Comments