log: (타동사) 일지에 기록하다
(마지막 화살표) JUL(java util logging)은 SLF4j API로 보낸다.
(중간 화살표) Log4J도 SLF4j API로 보낸다.
(처음 화살표) Logback이 SLF4j의 구현체이다.
Commons Logging, SLF4j는 실제 로깅을 하는 애들이 아니라 로거 API를 추상화해둔 interface 이다.
스프링 부트는 기본적으로 Commons Logging을 사용하는데 결국 SLF4j을 사용하고, SLF4j는 구현체인 Logback을 사용하여 로깅(기록)을 한다.
최종적으로 Logback을 쓴다.
스프링 부트 로깅의 기본 포맷
날짜 시간 / 로그 레벨 / PID / Thread 이름 / full package경로.class이름 / 메세지
디버깅 모드
일부 핵심 라이브러리(embedded container, Hibernate, and Spring Boot)만 디버깅 모드로
-
VM options: -Ddebug 또는
-
Program arguments:--debug
전부 다 디버깅 모드로
-
Program arguments:--trace
로거의 추가 설정
컬러 출력
[ application.properties ]
spring.output.ansi.enabled=always
파일 출력
logging.file 또는 logging.path
[ application.properties ]
logging.file.path=logs
로그 레벨 조정
logging.level.패지키 = 로그 레벨 (FATAL, ERROR, WARN, INFO, DEBUG, TRACE)
[ application.properties ]
logging.level.com.jueun.demo=DEBUG
로거 직접 찍어보기
package com.jueun.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class SampleRunner implements ApplicationRunner {
private Logger logger = LoggerFactory.getLogger(SampleRunner.class);
@Autowired
private String hello;
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("=====================");
logger.info(hello);
logger.info("=====================");
}
}
'Springboot' 카테고리의 다른 글
[spring boot] Test (0) | 2021.01.09 |
---|---|
[spring boot] 로거를 Log4j2로 변경하기 (0) | 2021.01.08 |
[spring boot] logging 커스터마이징 (0) | 2021.01.08 |
@Profile (0) | 2021.01.08 |
[spring boot] 외부 설정 (0) | 2021.01.08 |
SpringApplication (0) | 2021.01.06 |