日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Springboot项目中配置tomcta监控日志

發布時間:2024/10/5 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Springboot项目中配置tomcta监控日志 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

背景:在tomcat的access中打印出請求的情況可以幫助我們分析問題,通常比較關注的有訪問IP、線程號、訪問url、返回狀態碼、訪問時間、持續時間。

在Spring boot中使用了內嵌的tomcat,可以通過server.tomcat.accesslog配置tomcat 的access日志

tomcat的accesslog日志?

server.tomcat.accesslog.buffered=true server.tomcat.accesslog.enabled=true server.tomcat.accesslog.file-date-format=.yyyy-MM-dd server.tomcat.accesslog.pattern=%a %h %m %l %u %t %r %s %S %b %D %T %I server.tomcat.accesslog.prefix=access_log server.tomcat.accesslog.rename-on-rotate=false server.tomcat.accesslog.request-attributes-enabled=false server.tomcat.accesslog.rotate=true server.tomcat.accesslog.suffix=.log server.tomcat.accesslog.directory=tomcat-access-logs

比較常用的有(省略了前綴server.tomcat.accesslog.):

  • enabled,取值true、false,需要accesslog時設置為true
  • directory,指定access文件的路徑
  • pattern,定義日志的格式,后續詳述
  • rotate,指定是否啟用日志輪轉。默認為true。這個參數決定是否需要切換切換日志文件,如果被設置為false,則日志文件不會切換,即所有文件打到同一個日志文件中,并且file-date-format參數也會被忽略

tomcat日志路徑

server.tomcat.basedir=D:/logs(例)

主要字段:
server.tomcat.accesslog.pattern 解釋:

%a - Remote IP address 遠程IP地址 %A - Local IP address 本地IP地址 %b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent 返回給客戶端的數據字節數,- 表示沒有數據 %B - Bytes sent, excluding HTTP headers 與上面一樣,貌似是官方的bug,應該是一個包含 HTTP headers 一個不包含 %h - Remote host name (or IP address if enableLookups for the connector is false) %H - Request protocol %l - Remote logical username from identd (always returns '-') %m - Request method %p - Local port %q - Query string (prepended with a '?' if it exists, otherwise an empty string %r - First line of the request %s - HTTP status code of the response %S - User session ID %t - Date and time, in Common Log Format format %u - Remote user that was authenticated %U - Requested URL path %v - Local server name %D - Time taken to process the request, in millis 處理請求耗時,單位毫秒 %T - Time taken to process the request, in seconds 同上,單位秒 %I - current Request thread name (can compare later with stacktraces) 執行當前請求的線程名稱,輸出可以統計多少線程在工作。

Access log 也支持將cookie、header、session或者其他在ServletRequest中的對象信息打印到日志中,其配置遵循Apache配置的格式({xxx}指值的名稱):

%{xxx}i for incoming headers,request header信息
%{xxx}o for outgoing response headers,response header信息
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
%{xxx}t xxx is an enhanced SimpleDateFormat pattern (see Configuration Reference document for details on supported time patterns)
?

參考文章:https://blog.csdn.net/hrbeuwhw/article/details/81704549

https://blog.csdn.net/u013732378/article/details/100151205

?

?

總結

以上是生活随笔為你收集整理的Springboot项目中配置tomcta监控日志的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。