build.gradle
dependencies {
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.17.2'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.2'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.36'
implementation 'com.lmax:disruptor:3.4.4'
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.14'
application.yml
logging:
charset:
console: UTF-8
file: UTF-8
level:
root: info
com:
example: info
file.name: C:/logs/server.log
pattern.console:
pattern.file: "%d{HH:mm:ss.SSS} %-5level [%t] %logger{39} : %m%n"
logback:
rollingpolicy:
max-file-size: 10MB
max-history: 100
ApiController.java
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.message.SimpleMessage;
..
public class ApiController {
private final static org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger("ApiController");
..
String message = "hello";
// logMessage(level, marker, fqcn, location, message, throwable)
log.logMessage(Level.INFO, null , "ApiController", null, new SimpleMessage(message), null);
java run
java ... -DLOG_PATH=C:/logs -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -jar application.jar
스프링 부트 기본 파일 로그 보다 30% 정도의 성능이 향상된다.
'spring' 카테고리의 다른 글
javascript scroll to top (0) | 2024.10.17 |
---|---|
spring boot custom auto configuration (0) | 2024.10.12 |
spring boot 가상 스레드 (0) | 2024.10.12 |
spring boot 가상 스레드로 Async 및 Scheduled 어노테이션 사용 (0) | 2024.10.12 |
spring boot 가상 스레드로 Redis 사용 (0) | 2024.10.12 |