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

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 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连接池是否正常工作?

最佳答案

同意M Deinum的观点,在c3p0的log4j测试中,我使用的是logger,而不是category。即

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


另外,如果由于某种原因c3p0正在记录到发现的其他日志记录库中,则可以强制c3p0登录到log4j。在c3p0.properties文件中或作为VM的系统属性,添加

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


祝好运!

关于java - c3p0日志记录不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20101036/

10-14 19:54