2016년 7월 22일 금요일

Setting access log in spring boot application

You can set the access log setting in spring boot application.

- Sturucture
















- pom.xml



    4.0.0

    org.blog.test
    logback-valve-project
    1.0-SNAPSHOT

    
        org.springframework.boot
        spring-boot-starter-parent
        1.3.6.RELEASE
         
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            ch.qos.logback
            logback-access
            1.1.7
        

        
            ch.qos.logback
            logback-core
            1.1.7
        

    




- application.properties

server.tomcat.basedir=C:\\tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=logs
server.tomcat.accesslog.prefix=${user.name}.access
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.pattern=%h %l %u %user %date "%r" %s %b


- LogBackAccessApplication.java

package org.blog.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class LogBackAccessApplication {

    public static void main(String[] args) {
        SpringApplication.run(LogBackAccessApplication.class, args);
    }

    @RequestMapping("/server/info")
    public String getServerInfo() {
        return "server-info";
    }
}


- result

You can find the access log.


댓글 없음 :

댓글 쓰기