如何关闭 java c3p0 连接池库的登录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2976308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:08:52  来源:igfitidea点击:

how do I turn off logging in java c3p0 connection pooling lib?

javac3p0

提问by James

hey all, I'm just getting started with c3p0 for database connection pooling. It's attaching itself to my log4j output currently. How do I set logging off or at least to SEVERE level only for c3p0? I tried tweaking the properties file but not sure it's being picked up properly.

大家好,我刚刚开始使用 c3p0 进行数据库连接池。它目前将自己附加到我的 log4j 输出。如何仅为 c3p0 设置注销或至少设置为 SEVERE 级别?我尝试调整属性文件,但不确定它是否被正确拾取。

any ideas on how best to turn it off?

关于如何最好地关闭它的任何想法?

thanks

谢谢

UPDATE: this seems to work in the log4j.properties file

更新:这似乎适用于 log4j.properties 文件

log4j.logger.com.mchange.v2.c3p0.impl=INFO

log4j.logger.com.mchange=INFO

采纳答案by fasseg

If you use a log4j.xml file you can simple define a logger for the c3po package:

如果您使用 log4j.xml 文件,您可以简单地为 c3po 包定义一个记录器:

<logger name="com.mchange.v2.c3p0">
    <level value="SEVERE"/>
</logger>

There are analogous methods for log4j.properties. I think it's just:

log4j.properties 有类似的方法。我认为这只是:

log4j.logger.com.mchange.v2.c3p0=SEVERE

回答by Prashant Pandey

You can set log level by adding following lines in log4j.xml Logging at least at Error level is desired.

您可以通过在 log4j.xml 中添加以下行来设置日志级别,至少需要错误级别的日志记录。

< category name="com.mchange" additivity="false"> 
        < priority value="ERROR"/>
        < appender-ref ref="ASYNC"/>
     </ category>

If you really want to turn off c3P0 logging set property com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF

如果你真的想关闭 c3P0 日志设置属性 com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL=OFF

in c3p0-Config.properties

在 c3p0-Config.properties 中

or you can directly set this in code as an System property System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",MLevel.OFF);

或者您可以直接在代码中将其设置为系统属性 System.setProperty("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL",MLevel.OFF);

回答by crimean

I fixed problem with line of code:

我解决了代码行的问题:

com.mchange.v2.log.MLog.getLogger().setLevel(MLevel.INFO);

I am using log4j in my app.

我在我的应用程序中使用 log4j。

回答by Philippe Carriere

For those who are NOT using a configuration file, just to add the following in the code, before loading the connection pool.

对于那些不使用配置文件的人,只需在代码中添加以下内容,然后再加载连接池。

Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any other level
System.setProperties(p);

回答by Sarel Botha

I was getting messages like the following:

我收到如下消息:

Tue Feb 12 13:42:01 EST 2013 INFO: Profiler Event: [FETCH]  at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) duration: 0 ms, connection-id: 67, statement-id: 23, resultset-id: 27

This made me think that C3P0 was logging these messages. Actually the message is coming from the mysql connector because I enabled profiling by using a connection string like this:

这让我认为 C3P0 正在记录这些消息。实际上,该消息来自 mysql 连接器,因为我使用如下连接字符串启用了分析:

jdbc:mysql://localhost/database?profileSQL=true

Remove ?profileSQL=trueto make it stop logging these messages.

删除?profileSQL=true以使其停止记录这些消息。

回答by a4word

I am working on clojure, through korma and for the life of my I could not get any properties files to load (I am new to clojure so I blame myself). If you are in a similar boat, the following might help you out.

我正在通过 korma 研究 clojure,在我的一生中,我无法加载任何属性文件(我是 clojure 的新手,所以我责怪自己)。如果您在类似的船上,以下内容可能会对您有所帮助。

(System/setProperties 
  (doto (java.util.Properties. (System/getProperties))
    (.put "com.mchange.v2.log.MLog" "com.mchange.v2.log.FallbackMLog")
    (.put "com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL" "OFF")))

The is basically a clojure port of Philippe Carriere's answer above, thank you so much!

基本上是上面Philippe Carriere回答的clojure端口,非常感谢!