우리가 개발하는 프로그램에서는 다양한 에러들이 발생할 수도 있고, 당장은 발견되지 않았지만 추후에 발견하게 된 에러들을 추적하여 수정해야할 수도 있다. 때문에 프로그램이 실행되는 도중 기록을 남기는 것이 매우 중요한데, 이러한 작업을 로깅이라고 한다.
로그는 현재로서는 크게 중요하지 않아 일단 설정한 소스파일만 나열한다.
/spring/src/main/resources/properties/dev.properties
/spring/src/main/resources/properties/local.properties
/spring/src/main/resources/properties/prod.properties
#Database
#MariaDB.driverClassName=org.mariadb.jdbc.Driver
MariaDB.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
MariaDB.url=jdbc:log4jdbc:mariadb://leedohyun.asuscomm.com:2017/spring
MariaDB.username=
MariaDB.password=
/spring/src/main/resources/log4jdbc.log4j2.properties
log4jdbc.drivers=org.mariadb.jdbc.Driver
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
/spring/src/main/resources/logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<encoder>
<Pattern>
<!-- %d{yyyy-MM-dd HH:mm:ss} : 년월일 시분초 %thread : thread name %-5level
: log level , -5는 출력 고정폭 값 %logger{length} :Logger name의 이름, {length}는 자리수
%msg : log message %message은 alias %n : 줄바꿈 org.fusesource.jansi:jansi:1.8
가 필요함. Linux ,Mac OS X 기본적으로 지원함 <withJansi>true</withJansi>설정후 사용해야함 %highlight
: log level 별로 color가 다르게 나옴 -->
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</encoder>
</layout>
</appender>
<!-- mybatis query log setting -->
<logger name="jdbc" level="OFF" />
<logger name="jdbc.sqlonly" level="OFF" />
<logger name="jdbc.sqltiming" level="DEBUG" />
<logger name="jdbc.audit" level="OFF" />
<logger name="jdbc.resultset" level="OFF" />
<logger name="jdbc.resultsettable" level="OFF" />
<logger name="jdbc.connection" level="OFF" />
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
/spring/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.doh</groupId>
<artifactId>yun</artifactId>
<name>spring</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.2.8.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>2.0.0-alpha1</org.slf4j-version>
<org.mariadb.jdbc-version>2.6.2</org.mariadb.jdbc-version>
<junit-version>4.13</junit-version>
<mybatis-version>3.5.5</mybatis-version>
<mybatis-spring-version>2.0.5</mybatis-spring-version>
<logback-version>1.3.0-alpha5</logback-version>
<log4jdbc-version>1.16</log4jdbc-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Spring TestContext Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<!-- Spring JDBC -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- MariaDB Java Client -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${org.mariadb.jdbc-version}</version>
</dependency>
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis-version}</version>
</dependency>
<!-- MyBatis Spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybatis-spring-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<!-- Log4j Implemented Over SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<!-- JUL to SLF4J Bridge -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<!-- Logback Classic Module -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
<scope>compile</scope>
</dependency>
<!-- Logback Core Module -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback-version}</version>
</dependency>
<!-- Log4Jdbc Log4j2 JDBC 4 1 -->
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>${log4jdbc-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
참조
https://gmlwjd9405.github.io/2019/01/04/logging-with-slf4j.html
https://goddaehee.tistory.com/45
http://log4jdbc.brunorozendo.com/
https://kutar37.tistory.com/entry/slf4j-logback-%EC%84%A4%EC%A0%95?category=768676
'Spring' 카테고리의 다른 글
Spring Framework (9) - Bootstrap 설정 및 로그인, 회원가입 화면 구현 (0) | 2021.05.19 |
---|---|
Spring Framework (8) - Bill of Materials을 활용한 Spring Framework 버전 관리 (0) | 2021.05.19 |
Spring Framework (6) - MyBatis 설정 (0) | 2021.05.19 |
Spring Framework (5) - Database MariaDB 연동 (0) | 2021.05.19 |
Spring Framework (4) - 개발 환경 설정(Pom.xml 수정, Spring 최신버전 설정, 배포환경별 설정) (0) | 2021.05.19 |