Disable HikariPool logging

送分小仙女□ 提交于 2020-06-10 07:36:05

问题


This is perhaps a very simple question. How do i disable Hikari-CP debug logs? In my log file i have lots of these messages

DEBUG [.zaxxer.hikari.pool.HikariPool:] - Before cleanup pool stats HikariPool-0 (total=10, inUse=0, avail=10, waiting=0)
DEBUG [.zaxxer.hikari.pool.HikariPool:] - After cleanup pool stats HikariPool-0 (total=10, inUse=0, avail=10, waiting=0)

and in my log4jConfig.xml:

<logger name="org.zaxxer.hikari">
    <level value="error"/>
</logger>

Can someone please tell me what is wrong with the logger configuration?

Thanks!


回答1:


The logger name should be com.zaxxer.hikari not org.zaxxer.hikari.




回答2:


The class name is displaying in you DEBUG info: DEBUG [.zaxxer.hikari.pool.HikariPool:] - ... here the class name is zaxxer.hikari.pool.HikariPool, Just modify config file as being disaplayed.

I use logback logger, there is a file named logback.xml located in resources folder, to disable HikariPool logging, i write following config:

 <configuration>
...
    <logger name="com.zaxxer.hikari.pool.PoolBase" level="ERROR"/>
    <logger name="com.zaxxer.hikari.pool.HikariPool" level="ERROR"/>
    <logger name="com.zaxxer.hikari.HikariDataSource" level="ERROR"/>
</configuration>



回答3:


I use log4j properties, simple add these two lines:

log4j.category.com.zaxxer.hikari=INFO
log4j.logger.HikariPool=INFO



回答4:


You can set the levels of Hikari loggers dynamically:

import org.apache.log4j.Logger;
import org.apache.log4j.Level;

public class App{
     public static main(String[] args) {
         Logger.getLogger("com.zaxxer.hikari.pool.PoolBase").setLevel(Level.OFF);
         Logger.getLogger("com.zaxxer.hikari.pool.HikariPool").setLevel(Level.OFF);
         Logger.getLogger("com.zaxxer.hikari.HikariDataSource").setLevel(Level.OFF);
         Logger.getLogger("com.zaxxer.hikari.HikariConfig").setLevel(Level.OFF);
         Logger.getLogger("com.zaxxer.hikari.util.DriverDataSource").setLevel(Level.OFF);
     }
}

I have tested this on hikariCP 3.4.1 with log4j 1.2.17



来源:https://stackoverflow.com/questions/27274115/disable-hikaripool-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!