Tomcat 卡特琳娜日志记录

Tomcat catalina logging

我正在使用 SpringMVC 框架和 Java 8 进行开发。在 Tomcat catalina.out 文件中,日期时间戳和 threadid 没有与我的应用程序日志一起添加。

我得到如下日志

INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-9090"]
INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["https-jsse-nio-8443"]
INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
java.io.FileNotFoundException: /apps/opt/sws/logs
Request SecurityContextHolderAwareRequestWrapper
Beginning of the api method

我需要将日期时间戳和线程 ID 与我的应用程序一起添加 示例:-

2022-01-08 12:51:23:986[Thread - http-nio-exec-4id] INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-9090"]
2022-01-08 12:52:56:986[Thread - http-nio-exec-8id] INFO Request SecurityContextHolderAwareRequestWrapper
2022-01-08 12:58:45:986[Thread - http-nio-exec-9id] INFO Beginning of the api method
2022-01-08 12:58:55:986[Thread - http-nio-exec-47id] ERROR Exception happened while loading

请帮助我,我需要更改设置并提供任何示例。

您可以执行以下操作来实现此目的。将以下行添加到 log4j.properties.

java.util.logging.SimpleFormatter.format=%1$tF %1$tT [%4$-7s] %5$s %n

否则您还可以将 Tomcat 日志记录更改为 log4j。您可以参考 here.