traceId的产生
最好是由nginx来产生,对于高版本的nginx,采取以下方式
location / {
proxy_pass http://upstream;
proxy_set_header traceId $request_id;
}
定制 tomcat log access 格式:
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="[%{yyyy-MM-dd HH:mm:ss.SSS}t] [%{traceId}i] [%h] [%U] [%m] [%H] [%s] [%D] [%b]" />
示例如下:
[2018-12-20 16:26:34.871] [9417f18173cdd4cf65c7e2828771c416] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:35.079] [f9c4d53a01b9bbac8a092eb697df2de5] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:35.270] [f5fb776b8e8e985857abfec548922b2b] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:35.462] [b44b0615c4eaae9bf886e86fcb75efc2] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:35.662] [e75d13997b97b7e5eeb423a7ccf62c2f] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:35.860] [d97d4fe3cb0bd952b244d9a421572fe3] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:26:38.956] [f3ac78c9bc981b2b332c4e6a1773f97b] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
[2018-12-20 16:31:01.199] [191a9bc6ef8684083fb91d5a3a8f9388] [10.75.164.245] [/test] [GET] [HTTP/1.0] [404] [0] [-]
应用日志格式定义:
[时间] [日志级别] [请求ID] [remoteIp] [url] [threadName] (类名:行数) 日志内容
示例如下:
[2018-12-21 09:30:34.887] [-] [0:0:0:0:0:0:0:1] [GET] [/test_web/test.do] [HTTP/1.1] [404] [0] [-]
[2018-12-21 09:30:37.688] [-] [0:0:0:0:0:0:0:1] [GET] [/test_web/test.do] [HTTP/1.1] [404] [0] [-]
tomcat catilina日志格式
1catalina.org.apache.juli.AsyncFileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = [%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL] [%4$s] [%3$s] %5$s %6$s%n
[2018-12-21 09:42:01.994] [信息] [org.apache.tomcat.util.net.NioSelectorPool] Using a shared selector for servlet write/read
[2018-12-21 09:42:01.995] [信息] [org.apache.catalina.startup.Catalina] Initialization processed in 2344 ms
[2018-12-21 09:42:02.033] [信息] [org.apache.catalina.core.StandardService] Starting service Catalina
[2018-12-21 09:42:02.034] [信息] [org.apache.catalina.core.StandardEngine] Starting Servlet Engine: Apache Tomcat/8.0.53
5万+

被折叠的 条评论
为什么被折叠?



