I am trying to redirect java.util.logging messages logged by the oracle jdbc driver and the oracle ucp (universal connection pool) library, but not able to do so.
- The messages logged by my application using JUL get logged but the ones logged by the oracle libraries are not getting logged.
- My intent here is redirect JUL messages to Logback to have more fine grained logging through configuration. i.e. enabling logging at class level instead of package level which I assume is not possible in JUL configuration (java.util.config file).
Below is the sample test code. Do you have any suggestions on the above two points?
import oracle.ucp.jdbc.PoolDataSourceImpl;
import org.slf4j.bridge.SLF4JBridgeHandler;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Logger;
public class JavaUtilToSlf4jApp {
private static Logger logger = Logger.getLogger(JavaUtilToSlf4jApp.class.getName());
public static void main(String[] args) {
SLF4JBridgeHandler.install();
startConnectionPool();
logger.info("Info Message");
}
private static void startConnectionPool() {
PoolDataSourceImpl pds = new PoolDataSourceImpl();
try {
pds.setConnectionPoolName("Pool Name");
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
pds.setConnectionFactoryProperties(getOracleDataSourceProperties());
pds.setDataSourceName("Datasource Name");
pds.setServerName("machine-name");
pds.setPortNumber(1521);
pds.setMinPoolSize(1);
pds.setMaxPoolSize(1);
pds.setMaxIdleTime(1800);
pds.setValidateConnectionOnBorrow(true);
pds.setUser("user");
pds.setPassword("password");
pds.startPool();
} catch (SQLException e) {
throw new RuntimeException("Cannot create project datasource ", e);
}
try {
Connection connection = pds.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
logger.info("Connection established");
}
private static Properties getOracleDataSourceProperties() {
Properties p = new Properties();
p.put("driverType", "oci");
p.put("networkProtocol", "tcp");
p.put("serviceName", "servicename");
return p;
}
}