javalogginglog4j2c3p0

c3p0 log4j2 implementation


I inherited a java tomcat web project project and I am trying to get c3p0 logging enabled and I cannot get it working for the life of me.

I am using c3p0 with jdbc driver com.microsoft.sqlserver.jdbc.SQLServerDriver and this seems to work great.

I've done some research and there is no log4j2.properties file, but there is a log4j2.xml file that has logging def in it. I added c3p0 logger name in but I cannot seem to get it to work.

Regular logging is working. What the application uses is

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
private static Logger logger = LogManager.getLogger("TrackerLogger");
logger.info("HOLA");

I've tried adding this in various places but when i start up my java app, nothing is logging.

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

Here is my log4j2.file

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
    <Appenders>
        <RollingFile name="logFile" fileName="c:/Tracker/Logs/current.log" filePattern="c:/Tracker/Logs/%d{yyyy-MM-dd} tracker.log" immediateFlush="true" append="true">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X] [%t] %-5level - %msg%n"/>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
            </Policies>   
        </RollingFile>
    </Appenders>
    <Loggers>

        <Logger name="com.mchange.v2.c3p0" level="info">
            <AppenderRef ref="logFile"/>
        </Logger>
        <Root level="trace">
            <AppenderRef ref="logFile"/>
        </Root>
    </Loggers>
    
</Configuration>

It's probably something simple and stupid i am missing.

Any suggestions?


Solution

  • You might place in your c3p0.properties file (or as a System property)

    com.mchange.v2.log.MLog=log4j2
    

    c3p0 logs to its own logging facade, which supports fanning out to moust common log libraries.

    See "configuring logging" for more.