헤르메스 LIFE

[log4j2] Log4j2 설정 참고 본문

Spring Framework

[log4j2] Log4j2 설정 참고

헤르메스의날개 2022. 12. 11. 10:12
728x90

항상 뭔가 급하면 찾게 된다.


pom.xml

<properties>
	<org.slf4j-version>1.7.36</org.slf4j-version>
	<log4j-version>2.18.0</log4j-version>
</properties>

<!-- 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.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j-version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j-version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${log4j-version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>${log4j-version}</version>
    <type>pom</type>
    <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>
<dependency>
    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
    <version>1.16</version>
    <exclusions>
        <exclusion>
            <groupId>slf4j-api</groupId>
            <artifactId>org.slf4j.api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

log4j2.xml

<?xml version="1.0" encoding="UTF-8">
<Configuration>

    <Appenders>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
        </Console>
    </Appenders>

    <Loggers>

        <!-- Spring -->
        <Logger name="org.springframework" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>
        <Logger name="org.springframework.web.servlet.DispatcherServlet" level="DEBUG" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger
                name="org.springframework.context.support.ReloadableResourceBundleMessageSource"
                level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="org.hotswap" level="OFF" additivity="false">
        </Logger>

        <Logger name="jdbc.connection" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="jdbc.sqlonly" level="INFO" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="jdbc.sqltiming" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="jdbc.audit" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="jdbc.resultset" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Logger name="jdbc.resultsettable" level="OFF" additivity="false">
            <AppenderRef ref="console"/>
        </Logger>

        <Root level="ERROR">
            <AppenderRef ref="console"/>
        </Root>

    </Loggers>

</Configuration>

src/main/resources경로에 log4jdbc.log4j2.properties를 작성한다.

log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
.dump.sql.maxlinelength=0

https://hermeslog.tistory.com/643

 

[Log] DriverSpy 설정

net.sf.log4jdbc.sql.jdbcapi.DriverSpy

hermeslog.tistory.com

 

728x90