Search code examples
javaspringlog4jconnection-poolingc3p0

Separate log file for c3p0 datasource


We have several datasources in our project. c3p0 used as jdbc connecton pool.

Log file contains mixed datasources output. Is it posible to create separate log file for each datasource?

Spring configutaion file:

<bean id="firstDS" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <properties/>
/bean>
<bean id="secondDS" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <properties/>
</bean>

Log4j configuration:

<logger name="com.mchange.v2" additivity="false">
    <level value="DEBUG"/>
    <appender-ref ref="c3p0.appender"/>
</logger>

Solution

  • unfortunately, c3p0's loggers are defined on a per-class, not per-instance basis, so there's not an easy way to segregate logging by instance. loggers are very fine-grained by class though; to avoid some of the noise you can set permissive log-levels only on the classes that most interest you.