Spring Boot 3中无法开启Oracle UCP的TRACE/FINEST级别日志
Spring Boot中Oracle UCP日志无法正常输出的问题
我已花费数日尝试在Spring Boot应用中开启Oracle UCP日志,但未成功。以下是我用于查看根日志器和Oracle日志器级别、处理器的代码:
@SpringBootApplication @EnableAsync @Slf4j public class RabotApplication { public static void main(String[] args) { SpringApplication.run(RabotApplication.class, args); System.out.println("--- LIST OF ACTIVE LOGGERS ---"); java.util.Enumeration<String> loggerNames = java.util.logging.LogManager.getLogManager().getLoggerNames(); while (loggerNames.hasMoreElements()) { String name = loggerNames.nextElement(); if (name.contains("oracle") || name.isEmpty()) { Logger logger = java.util.logging.Logger.getLogger(name); System.out.println("Logger found: " + name + " [Level: " + logger.getLevel() + "]"); System.out.println("UseParentHandlers: " + logger.getUseParentHandlers()); for (java.util.logging.Handler h : logger.getHandlers()) { System.out.println("Handler: " + h.getClass().getName() + " level: " + h.getLevel()); } logger.finest("Test finest message"); } } System.out.println("-------------------------------------"); } }
输出结果如下:
--- LIST OF ACTIVE LOGGERS --- Logger found: [Level: INFO] UseParentHandlers: true Handler: org.slf4j.bridge.SLF4JBridgeHandler level: ALL Logger found: oracle.ucp [Level: FINEST] UseParentHandlers: true 2026-04-17T13:01:05.376+03:00 TRACE 33153 --- [rabot] [ main] oracle.ucp : Test finest message Logger found: oracle.ucp.jdbc [Level: FINEST] UseParentHandlers: true 2026-04-17T13:01:05.376+03:00 TRACE 33153 --- [rabot] [ main] oracle.ucp.jdbc : Test finest message Logger found: oracle.jdbc [Level: FINEST] UseParentHandlers: true 2026-04-17T13:01:05.376+03:00 TRACE 33153 --- [rabot] [ main] oracle.jdbc : Test finest message -------------------------------------
如您所见,我能看到自定义的Finest消息,但应用运行并使用连接池时,没有任何日志显示。以下是我使用的Oracle依赖库:
<dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc11</artifactId> <version>23.26.1.0.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ucp</artifactId> <version>23.26.1.0.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.oracle.database.security</groupId> <artifactId>oraclepki</artifactId> <version>23.26.1.0.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.oracle.database.security</groupId> <artifactId>osdt_cert</artifactId> <version>21.21.0.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.oracle.database.security</groupId> <artifactId>osdt_core</artifactId> <version>21.21.0.0</version> <scope>compile</scope> </dependency>
内容的提问来源于stack exchange,提问作者Matthew
相关产品推荐
相关产品推荐

