일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 리눅스
- CSS
- 파이썬경로설정
- 욜로모델
- 광주광역시운암동
- 레벨분리
- 우분투1804
- 스프링부트
- opencvwithcudano
- ls-ld
- 스프링부트로깅
- jsp렌더링
- fastapi
- gitbranch추가
- 로그아웃정의
- 표준프레임워크
- importjetson
- db에로그저장
- root접근하기
- 빈생성에러
- 권한확인명령어
- git최신코드반영
- install에러
- git명령어
- gitfetchpull
- git협업하기
- (✿´‿`)
- 운암동점심
- 운암동돈까스맛집
- 리눅스selinux
Archives
- Today
- Total
개발자 구겹이
log4j 로 로깅하기 본문
스프링부트 프로젝트는 기본적으로 logback을 사용해서 로깅한다고 함!
때문에
log4j로 교체하여 로깅하기 위해서는 logback이 작동하지 못하게 하고, log4j 관련 lib이 활성화되도록 해주어야 함
>>
1. 환경설정 [pom.xml]
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.1</version>
<scope>compile</scope>
</dependency>
2. 환경설정[src/main/resources/log4j2.xml] 파일 추가
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="LogFile" fileName="logs/loggingforlog.log" append="true">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<!-- SnmpLogger 전용 설정 -->
<Logger name="com.pws_01.iloveyou.log4j.Logger" level="info" additivity="false">
<AppenderRef ref="LogFile"/>
<AppenderRef ref="Console"/>
</Logger>
<!-- Root logger 설정 -->
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
3. 환경설정[application.properties]
logging.config=classpath:log4j2.xml
4. 로그파일에 패턴을 살리고 싶다면, 별개의 클래스를 만들어서 StringBuild해주기
#추가업로드예정⎛;c*•ヮ•⎞
!참고!
.xml 파일 내에 Appender > File >> PatternLayout 정의 없이 파일 로깅하면 xml형식의 로깅이 수행됨
'java > springboot' 카테고리의 다른 글
@Autowired는 언제 붙이는가 (0) | 2025.06.18 |
---|---|
스프링부트 jsp 렌더링 관련 설정 (0) | 2025.05.02 |
단순 파일 업로드 스프링부트 자바코드 (0) | 2024.11.04 |
[스프링부트 기본 환경설정] 뷰리졸버 설정하기 (0) | 2024.09.30 |
[springboot]웹 구동 시 setting - default-web-mapping-root! (0) | 2024.05.28 |