I have my spring application, which is running on the Tomcat server, and I have an acsess_log
file, which is written logs that I need to use in java Spring Boot.
It looks like that:
IP - - [17/Feb/2023:17:27:20 +0400] "GET /web-services/112233.jpg HTTP/1.1"
IP - - [17/Feb/2023:17:27:29 +0400] "GET /web-services/ HTTP/1.1" 200 189
IP - - [17/Feb/2023:17:27:29 +0400] "GET /web-services/112233.jpg HTTP/1.1" 304
Here Tomcat writes logs, which are sent to visiting URL/SITE.
I need to print/read it into Java and get access to them.
Is there any possible way to do it?
My application.properties
:
spring.mvc.view.prefix= /WEB-INF/jsp/
spring.mvc.view.suffix= .jsp
server.tomcat.accesslog.enabled= true
I try many ways to solve it, I try to inject AccessLogValve
but it doesn't work:
@GetMapping(value = "/")
public String root(AccessLogValve acc) {
// When I try to call AccessLogValve methods, it's always null
return "index";
}
I add some properties in application.properties but it doesn't help:
server.tomcat.accesslog.directory= "/dev"
server.tomcat.accesslog.prefix= stdout
server.tomcat.accesslog.buffered= false
server.tomcat.accesslog.suffix=
server.tomcat.accesslog.file-date-format=
server.tomcat.accesslog.pattern= "[ACCESS] %{org.apache.catalina.AccessLog.RemoteAddr}r %l %t %D %F %B %S vcap_request_id:%{X-Vcap-Request-Id}i"
Please help me