-
3. SpringBoot + Logback 설정Project/React+Java 2022. 7. 21. 17:26
https://github.com/dchkang83/project-board
1. logback 의존성 추가
https://mvnrepository.com/search?q=logback
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.11'
2. application.yml 설정
# 파일 삭제 # /project-board/back-end/gundam/src/main/resources/application.properties # 파일 추가 # /project-board/back-end/gundam/src/main/resources/application.yml # server server: port: 8080 servlet: context-path: / # encoding: # charset: UTF-8 # enabled: true # force: true # log level logging: logback: rollingpolicy: file-name-pattern: "/Users/djkang/dev/gundam/product-src/logs/abc.%d{yyyy-MM-dd}.%i" pattern: file: "[%d{HH:mm:ss.SSS}][%-5level][%logger.%method:line%line] - %msg%n" file: name: /Users/djkang/dev/gundam/product-src/logs/abc.log max-history: 300 level: '[com.main.gundam.sample]': INFO org: springframework: INFO
3. 로그 확인 코드 추가
package com.main.gundam.controller; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; // import org.slf4j.Logger; // import org.slf4j.LoggerFactory; @RestController @RequestMapping(value = "/main", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE}) @RequiredArgsConstructor @Slf4j public class RestApiController { // private static final Logger logger = LoggerFactory.getLogger(RestApiController.class); @GetMapping("home") public String home() { log.info("home"); // logger.info("home"); return "<h1>home</h1>"; } @GetMapping("/get/{userId}") public String get(@PathVariable(value = "userId") final String userId) { // logger.info("get user"); log.info("get user"); return userId; } }
4. 설정된 경로에 로그파일 생기는지 확인
'Project > React+Java' 카테고리의 다른 글
6. Spring Boot + Spring Security + JWT + access token (0) 2022.07.22 5. SpringBoot + Rancher + VsCode Mysql Client (0) 2022.07.22 4. SpringBoot + JPA + H2 database (0) 2022.07.21 2. SpringBoot + Controller TestCase 설정 확인 (0) 2022.07.21 1. VsCode + SpringBoot + Gradle (0) 2022.07.21