[Spring Boot #9] 스프링 부트 로깅(Logging)
- 📚 Spring/Spring Boot
- 2020. 4. 28. 18:24
| 스프링 부트 로깅( Spring Boot Logging )
스프링 부트에서는 로깅 설정을 자동적으로 지원한다. slf4j 로깅 파사드 (로깅 모듈을 추상화 한것)를 통해 logback을 지원한다.
즉, 실제 콘솔에 찍어주는 것은 logback이다.
package org.kyhslam.springinit;
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 {
// slf4j 로깅 파사드를 통해 logback 로깅 모듈을 지원
private Logger logger = LoggerFactory.getLogger(SampleRunner.class);
@Autowired
private String hello;
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("logger ================");
logger.info(hello);
logger.info("logger ================");
}
}
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(Application.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.run(args);
}
}
실행하면 아래와 같이 log가 출력되는 것을 볼 수 있다.
| application.properties를 통한 로깅 설정
application.properties를 통해 다음과 같이 로깅 설정을 할 수 있다.
## application.properties
## 콘솔창에 출력되는 로깅 메세지를 색으로 구분해서 출력
spring.output.ansi.enabled=always
## 로그 메세지가 저장되는 디렉토리를 지정
logging.path=logs
logs 폴더에 로그가 출력되는 것을 볼수 있다.
'📚 Spring > Spring Boot' 카테고리의 다른 글
[Spring Boot #11] 스프링 웹 MVC - HttpMessageConverters (0) | 2020.05.03 |
---|---|
[Spring Boot #10] 스프링 부트 테스트 (Spring Boot Test) (0) | 2020.04.29 |
[Spring Boot #8] 스프링 부트 프로파일(Profile) (0) | 2020.04.28 |
[Spring Boot #7] 스프링 부트 외부 설정 (0) | 2020.04.27 |
[Spring Boot #6] 이벤트 리스터 (0) | 2020.04.26 |