Marsellus Wallace
Marsellus Wallace

Reputation: 18601

BoneCP not logging SQL statements

I'm using an embedded Jetty 8 Server with the jetty-maven-plugin. I cannot get BoneCP to log the statements that are executed. Am I doing anything wrong? Are there any workarounds?

This is my BoneCPDataSource:

<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/DSTest</Arg>
    <Arg>
        <New class="com.jolbox.bonecp.BoneCPDataSource">
            <Set name="driverClass">com.mysql.jdbc.Driver</Set>
            <Set name="jdbcUrl">my_url</Set>
            <Set name="username">my_username</Set>
            <Set name="password">my_password</Set>
            <Set name="partitionCount">5</Set>
            <Set name="minConnectionsPerPartition">5</Set>
            <Set name="maxConnectionsPerPartition">50</Set>
            <Set name="acquireIncrement">5</Set>
            <Set name="idleConnectionTestPeriod">30</Set>
            <Set name="logStatementsEnabled">true</Set>
        </New>
    </Arg>
</New>

This is my log4j property file loaded by the servlet through the servlet context:

log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

Thanks

Upvotes: 3

Views: 2984

Answers (1)

Wuaner
Wuaner

Reputation: 969

just see the code in com.jolbox.bonecp:

package com.jolbox.bonecp;

public class PreparedStatementHandle extends StatementHandle implements
     PreparedStatement {
    // @Override
    public boolean execute() throws SQLException {
        checkClosed();
        try {
            if (this.logStatementsEnabled && logger.isDebugEnabled()){
                logger.debug(PoolUtil.fillLogParams(this.sql, this.logParams));
            }
         ...
    }
}   

So besides add logStatementsEnabled setting for bonecp,you also must turn on bonecp's log level to DEBUG or ALL in log4j.properties. here is a example:

log4j.logger.com.jolbox.bonecp=DEBUG

Details about log4j Level.

Upvotes: 4

Related Questions