지구용사 2024. 4. 24. 15:47

운영시스템에선 System.out.println()가은 시스템 콘솔을 사용해서 정보를 출력하지 않고, 별도의 로깅 라이브러리를 사용하여 로그를 출력한다.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogTestController {
    private final Logger log = LoggerFactory.getLogger(getClass()); //현클레스 지정

    @RequestMapping("/log-test")
    public String logTest() {
        String name = "Spring";
        log.info("info log = {}", name);
        return "OK";
    }
}

 

 

로그 레벨 : TRACE > DEBUG > INFO > WARN > ERROR

개벌서버는 debug, 운영 서버는 info를 출력한다.

//application.properties

#전체 로그 레벨 설정(기본 info)
logging.level.root=info

#hello.springmvc 패키지와 그 하위 로그 레벨 설정
logging.level.hello.springmvc=debug

 

 


 

🔗 강의 링크

https://inf.run/Gmptq