> For the complete documentation index, see [llms.txt](https://blakes-organization.gitbook.io/rainsister/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blakes-organization.gitbook.io/rainsister/springboot-2.x/log/log4j2.md).

# Log4j2 사용해보기

pom.xml 에  spring-boot-starter-log4j2 추가 , 기본 spring-boot-starter-logging 는 배제&#x20;

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
```

application.properties

```
logging.config=classpath:log4j2.xml
```

resource 폴더 에 log4j2.xml 파일 생성.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>
```

여기서 log4j2 에 대한 궁금한 부분은  [여기](https://logging.apache.org/log4j/2.x/manual/configuration.html) 를 클릭하여 더 많은 정보를 찾아봐라!

여기서 궁금한것 그램 내가 위에서 적용한 로그 모듈이 log4j2 인지 아니면 기존 Logback 인지 어떻게 알지? 방법은 간단하다. debug 모드로 실행후 임의 포인트를 찍고 로그상태를 확인 해보면 알수 있다.

### 기존 Logback 일경우&#x20;

<figure><img src="/files/tq8n5HglidLJTDlPPxn6" alt=""><figcaption></figcaption></figure>

새로 적용된 Log4j2 경우.

<figure><img src="/files/kMZQpNhV03XiKNMlBNCR" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Log4j2  에 큰 버그가 발견 되어 현재 기준 2.17.0 를 사용하라고 명시되어있다고 한다. 하지만  Springboot 2.6.2+ 에서 이미 2.17.0 를 적용하여기때문에 별도의 변경작없이 없도 된다. 또는 2.17.1  이나 더 높은 버전을 사용해도 좋다.
{% endhint %}

끝!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blakes-organization.gitbook.io/rainsister/springboot-2.x/log/log4j2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
