2019.08.05

 

https://mvnrepository.com/search?q=log4j

 

Maven Repository: log4j

SLF4J LOG4J-12 Binding Last Release on Jun 13, 2019

mvnrepository.com

 

 

 pom.xml dependency 추가

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
 
<!-- 기본값:logback 제외 exclusion:spring-boot-starter-logging -->
<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>
 
<!-- log4j2  설정 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>
</dependency>
<dependency>
    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
    <version>1.16</version>
</dependency>
 
 

 

 application.properties 설정

1
2
3
4
5
6
7
8
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/DB이름?serverTimezone=UTC&characterEncoding=UTF8
spring.datasource.username=DB아이디
spring.datasource.password=DB
logging.config=src/main/resources/log4j2.xml
 
 
 

 

 

 src/main/resources 하위에 파일 추가

 

log4j2.xml
0.00MB
log4jdbc.log4j2.properties
0.00MB

 

 

 

 

 log4j2.xml 설정

 

로그 레벨
로그 레이아웃

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" monitorInterval="30">
    <Properties>
        <Property name="LOG_FORMAT">%d{yyyy-MM-dd HH:mm:ss} %p %m%n</Property>
    </Properties>
 
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${LOG_FORMAT}"/>
        </Console>
    </Appenders>
 
    <Loggers>
        <!-- Log everything in custom package -->
        <Logger name="com.boraji.tutorial.springboot" level="error" additivity="false">
          <AppenderRef ref="Console" />
        </Logger>
    
        <!-- Log everything in Spring Boot -->
        <Logger name="org.springframework.boot" level="error" additivity="false">
          <AppenderRef ref="Console" />
        </Logger>
            
        <!-- Log everything in Spring Core -->
        <Logger name="org.springframework.core" level="error" additivity="false">
          <AppenderRef ref="Console" />
        </Logger>
        
        <Logger name="jdbc" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.sqlonly" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.sqltiming" level="info" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.audit" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.resultset" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.resultsettable" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="jdbc.connection" level="error" additivity="false">
            <AppenderRef ref="Console" />
        </Logger>
        
        <Root level="error">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>
 
 

 

 

 

 

로그 화면

 

 

+ Recent posts