I have one service AccessLogsApplication in which i have one controller HelloWorld. I want to print every incoming request in separate log file called access_log.log in spring boot.
@RestController
public class HelloWorld {
private static final Logger log = LoggerFactory.getLogger(HelloWorld.class);
@RequestMapping(value = "/hello/1", method = RequestMethod.GET)
public String getHello() {
log.info("In method 1");
return "helloWorld";
}
@RequestMapping(value = "/hello/2", method = RequestMethod.GET)
public String getHelloFromUser() {
log.info("In method 2");
return "helloWorld From Sudhanshu Saini";
}
}
Here is my application.properties
spring.application.name=HelloWorld
server.port=8080
server.tomcat.accesslog.buffered=true
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=logs
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.pattern="%h %l %u %t %r %s %b %D"
logging.level.root=warn
logging.level.com.saini.access_logs=debug
logging.path=logs
logging.file=${logging.path}/hello_service.log
I want to log every in coming request for this service. like this (This is manually written by me not access logs)-
[03/May/2019:16:37:52 +0530] "GET /hello/1 HTTP/1.0" 200 2
[03/May/2019:16:37:52 +0530] "GET /hello/2 HTTP/1.0" 200 2
Access logs are not working in spring boot. Its not creating a file access_log.log