本文介绍了c3p0日志记录不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有得到c3p0日志记录,我的 log4j.properties 文件如下:

I am not getting c3p0 logging, my log4j.properties file is as below:

log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug

log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE

log4j.appender.c3p0=org.apache.log4j.DailyRollingFileAppender
log4j.appender.c3p0.File=/var/log/fni/c3p0.log
log4j.appender.c3p0.layout=org.apache.log4j.PatternLayout
log4j.appender.c3p0.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.c3p0.DatePattern='.'yyyy-MM-dd

# c3p0 logger
log4j.category.com.mchange.v2.log.MLog=info, c3p0
log4j.category.com.mchange.v2.c3p0=info, c3p0
log4j.category.com.mchange.v2.resourcepool=debug, c3p0

下面是一部分我的Spring配置

Below is part of my Spring Config

<bean
    id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <property name="configLocation">
        <value>
            classpath:hibernate.cfg.xml
        </value>
    </property>

    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.c3p0.min_size">3</prop>
                <prop key="hibernate.c3p0.max_size">20</prop>
                <prop key="hibernate.c3p0.timeout">300</prop>
                <prop key="hibernate.c3p0.max_statements">50</prop>
                <prop key="hibernate.c3p0.idle_test_period">3000</prop>
            </props>
     </property>
</bean>

<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
    <property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;DatabaseName=sample" />
    <property name="user" value="sa" />
    <property name="password" value="sa@123" />

</bean>

但是我正在获取休眠日志,并且还添加了c3p0 jar文件,我缺少了什么?如何知道我的c3p0连接池是否正常工作?

However I am getting hibernate log and I have also c3p0 jar file added, what I am missing? How to know my c3p0 connection pooling is working or not?

推荐答案

在我对c3p0的log4j测试中,我同意Deinum。使用过记录器,而不是类别。即

agreeing with M Deinum, in my log4j tests of c3p0, i've used logger, not category. i.e.

log4j.logger.com.mchange.v2.c3p0=INFO,c3p0
log4j.logger.com.mchange.v2.resourcepool=DEBUG,c3p0

此外,如果需要,您可以强制c3p0登录到log4j由于某种原因,它正在记录到已找到的其他记录库中。在c3p0.properties文件中或作为VM的系统属性,添加

also, you can force c3p0 to log to log4j if for some reason it is logging to some other logging library it has found. in a c3p0.properties file or as a System property to your VM, add

com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog

祝你好运!

这篇关于c3p0日志记录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:30