반응형
gradle 설정
// 기본 로거와 충돌방지위해 exclude 설정
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
}
//dependencies 추가
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
resources/log4j2.xml 추가
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" monitorInterval="5">
<Properties>
<Property name="logFileName">log</Property>
<Property name="consoleLayout">[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] [%c{1}:%L] - %m%n</Property>
<Property name="fileLayout">%d [%t] %-5level %c(%M:%L) - %m%n</Property>
</Properties>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="${consoleLayout}" />
</Console>
<RollingFile name="file"
fileName="logs/${logFileName}.log"
filePattern="logs/${logFileName}.%d{yyyy-MM-dd}.log">
<PatternLayout pattern="${fileLayout}" />
<Policies>
<SizeBasedTriggeringPolicy size="20 MB"/>
<TimeBasedTriggeringPolicy interval="1" /> <!-- 파일패턴의 날짜 포매시 초단위로 설정되어 있을 경우 1초에 한번씩 trigger -->
</Policies>
<DefaultRolloverStrategy max="5" fileIndex="max" >
<Delete basePath="/logs" maxDepth="3">
<IfLastModified age="10d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<!--TRACE > DEBUG > INFO > WARN > ERROR > FATAL -->
<Loggers>
<logger name="org.springframework" level="INFO" additivity="false" >
<AppenderRef ref="console" />
</logger>
<!-- sql binding variables logging -->
<logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE" additivity="false">
<AppenderRef ref="console" />
</logger>
<!-- sql logging -->
<logger name="org.hibernate.SQL" level="DEBUG" additivity="false" >
<AppenderRef ref="console" />
</logger>
<!-- ROOT logger-->
<Root level="ERROR">
<AppenderRef ref="console" />
<AppenderRef ref="file" />
</Root>
</Loggers>
</Configuration>
application.properties 수정 (hibernate 설정)
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.highlight_sql=true
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type=trace
hibernate logging example
sql :
format이 정돈되고 highlight로 보기 편하게 출력된다.
binding data :
binding data 및 select data도 출력된다.
※ 참고
반응형
'개발 > java_spring' 카테고리의 다른 글
[JPA] native query 에서 @변수 사용 시 오류 (0) | 2023.01.10 |
---|---|
[Spring Boot] JPA native query to dto throw error (0) | 2022.12.19 |
[Spring boot] JPA hibernate second level cache with redisson (0) | 2022.12.01 |
[Spring Boot] Jwt (0) | 2022.11.11 |
[Spring Boot]JPA @query null Parameter (0) | 2022.10.18 |