https://mvnrepository.com/
1. Apache Log4j Core
2. Apache Log4j API » 2.20.0
3. pom.xml에 dependency 추가하기
4. src/main/resources 폴더 생성 -> log4j2.xml 파일
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Properties>
<Property name="logNm">SpringProject_Log4j2</Property>
<Property name="layoutPattern">[%d{yyyy/MM/dd HH:mm:ss,SSS}] [%t] [%-5level] [%logger{36}] %m%n</Property>
</Properties>
<Appenders>
<Console name="Console_Appender" target="SYSTEM_OUT">
<PatternLayout pattern="${layoutPattern}"/>
</Console>
<RollingFile name="File_Appender" fileName="logs/${logNm}.log" filePattern="logs/${logNm}_%d{yyyy-MM-dd}_%i.log.gz">
<PatternLayout pattern="${layoutPattern}"/>
<Policies>
<SizeBasedTriggeringPolicy size="1000KB"/>
<TimeBasedTriggeringPolicy interval="1"/>
</Policies>
<DefaultRolloverStrategy max="10" fileIndex="min"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO" additivity="false">
<AppenderRef ref="Console_Appender"/>
<AppenderRef ref="File_Appender"/>
</Root>
<Logger name="org.springframework" level="DEBUG"
additivity="false">
<AppenderRef ref="Console_Appender" />
<AppenderRef ref="File_Appender"/>
</Logger>
<!--하단 name에 본인이 사용하는 package명으로 수정할 것-->
<Logger name="com.app.controller" level="INFO" additivity="false">
<AppenderRef ref="Console_Appender" />
<AppenderRef ref="File_Appender"/>
</Logger>
<Logger name="org.springframework" level="INFO" additivity="false">
<AppenderRef ref="Console_Appender" />
</Logger>
<Logger name="jdbc.audit" level="WARN" additivity="false">
<AppenderRef ref="Console_Appender" />
<AppenderRef ref="File_Appender"/>
</Logger>
<Logger name="jdbc.resultset" level="INFO" additivity="false">
<AppenderRef ref="Console_Appender" />
<AppenderRef ref="File_Appender"/>
</Logger>
<Logger name="jdbc.connection" level="WARN" additivity="false">
<AppenderRef ref="Console_Appender" />
<AppenderRef ref="File_Appender"/>
</Logger>
</Loggers>
</Configuration>
//선언 부분
private static final Logger Log = LogManager.getLogger(ReservationPaymentController.class);
//로그 출력
Log.info("searchReservationMap2 info");
Log.info("{} search {} param map {}", "0번째위치", "1번째위치", map);
Log.error("searchReservationMap2 error");
Log.warn("searchReservationMap2 warn");
//설정에서 레벨이 INFO로 되어있기 때문에 debug레벨은 출력이 되지 않는다.
//설정에서 level="DEBUG"로 수정해야 출력이 된다.
Log.debug("searchReservationMap2 debug");
Log4Jdbc Log4j2 JDBC 4 1 » 1.16
root-context.xml
<bean class="org.apache.commons.dbcp2.BasicDataSource" id="data_source">
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy" />
<property name="url" value="jdbc:log4jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="scott" />
<property name="password" value="tiger" />
</bean>
Project Lombok » 1.18.28
pom.xml에 dependency 추가하기
이클립스가 인식을 못하는 경우
lombok 다운로드
https://projectlombok.org/download
DTO를 생성하는 경우
getter, setter, 생성자 등을 어노테이션을 통해서 직접 작성하지 않아도 생성해주는 라이브러리
@AllArgsConstructor @NoArgsConstructor
@Data //getter setter tostring
public class ReservationDto {
String roomNumber;
String customerNumber;
}