gpt4 book ai didi

java - Spring Boot 启用 http 请求日志记录(访问日志)

转载 作者:IT老高 更新时间:2023-10-28 20:54:44 24 4
gpt4 key购买 nike

spring boot提供的嵌入式tomcat服务器如何开启访问日志?我已经在 application.properties 中尝试过,但它没有创建文件,也没有记录到控制台。

server.tomcat.access-log-enabled=true
server.tomcat.access-log-pattern=%a asdasd
logging.file=/home/mati/mylog.log

最佳答案

这是一种让它们显示在控制台或您选择的任何文件中的方法。声明 Tomcat 的 RequestDumperFilter在任何 @Configuration 类中:

@Bean
public FilterRegistrationBean requestDumperFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
Filter requestDumperFilter = new RequestDumperFilter();
registration.setFilter(requestDumperFilter);
registration.addUrlPatterns("/*");
return registration;
}

这就是输出:

http-nio-8765-exec-1 START TIME        =30-may-2016 12:45:41
http-nio-8765-exec-1 requestURI=/info
http-nio-8765-exec-1 authType=null
http-nio-8765-exec-1 characterEncoding=UTF-8
http-nio-8765-exec-1 contentLength=-1
http-nio-8765-exec-1 contentType=null
http-nio-8765-exec-1 contextPath=
http-nio-8765-exec-1 cookie=JSESSIONID=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1 header=host=mies-057:8765
http-nio-8765-exec-1 header=connection=keep-alive
http-nio-8765-exec-1 header=accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
http-nio-8765-exec-1 header=upgrade-insecure-requests=1
http-nio-8765-exec-1 header=user-agent=Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
http-nio-8765-exec-1 header=referer=http://mies-057:1111/
http-nio-8765-exec-1 header=accept-encoding=gzip, deflate, sdch
http-nio-8765-exec-1 header=accept-language=es-ES,es;q=0.8
http-nio-8765-exec-1 header=cookie=JSESSIONID=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1 locale=es_ES
http-nio-8765-exec-1 method=GET
http-nio-8765-exec-1 pathInfo=null
http-nio-8765-exec-1 protocol=HTTP/1.1
http-nio-8765-exec-1 queryString=null
http-nio-8765-exec-1 remoteAddr=192.168.56.1
http-nio-8765-exec-1 remoteHost=192.168.56.1
http-nio-8765-exec-1 remoteUser=null
http-nio-8765-exec-1 requestedSessionId=E7259F5F9ED6B04CBE5A294C5F8CA5C6
http-nio-8765-exec-1 scheme=http
http-nio-8765-exec-1 serverName=mies-057
http-nio-8765-exec-1 serverPort=8765
http-nio-8765-exec-1 servletPath=/info
http-nio-8765-exec-1 isSecure=false
http-nio-8765-exec-1 ------------------=--------------------------------------------
http-nio-8765-exec-1 ------------------=--------------------------------------------
http-nio-8765-exec-1 authType=null
http-nio-8765-exec-1 contentType=application/json;charset=UTF-8
http-nio-8765-exec-1 header=Strict-Transport-Security=max-age=31536000 ; includeSubDomains
http-nio-8765-exec-1 header=X-Application-Context=EDGE:8765
http-nio-8765-exec-1 header=Content-Type=application/json;charset=UTF-8
http-nio-8765-exec-1 header=Transfer-Encoding=chunked
http-nio-8765-exec-1 header=Date=Mon, 30 May 2016 10:45:41 GMT
http-nio-8765-exec-1 status=200
http-nio-8765-exec-1 END TIME =30-may-2016 12:45:41
http-nio-8765-exec-1 ===============================================================

然后将其作为任何标准 Spring Boot 日志进行管理。

关于java - Spring Boot 启用 http 请求日志记录(访问日志),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23325389/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com