๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Spring

[Spring] - ๋กœ๊น…: Log4j, Log4j2, Slf4j, Logback

by ์ฃผ๋ฐœ2 2021. 9. 15.
๋ฐ˜์‘ํ˜•

๐Ÿ“Ž Logging - Log4j, Log4j2, Slf4j, Logback

 ๋กœ๊ทธ(Log) ๋Š” ๊ธฐ๋ก์„ ๋‚จ๊ธฐ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋กœ๊ทธ๋ฅผ ํ†ตํ•ด ์†Œํ”„ํŠธ์›จ์–ด์˜ ๊ฐœ๋ฐœ์ด๋‚˜ ์šด์˜ ์‹œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์ ์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์„๋•Œ ๊ฐ€์žฅ ๋จผ์ € ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ๋กœ๊ทธ๋ฅผ ๋ณด๋Š” ๊ฒƒ์ด๋ฏ€๋กœ, ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธฐ๋Š” ๊ฒƒ์€ ๊ต‰์žฅํžˆ ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์‹ค์ œ ์†Œํ”„ํŠธ์›จ์–ด์—์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„๋•Œ, ์ ์žฌ์ ์†Œ์— ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ์ด ๋˜๊ณ ์žˆ๋‹ค๋ฉด ๋ฌธ์ œ์˜ ์›์ธ์— ๋Œ€ํ•ด ์ •ํ™•ํ•œ ํŒŒ์•…์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Java์—์„œ๋Š” Log4j, Log4j2, Slf4j, Logback ๋“ฑ ๋‹ค์–‘ํ•œ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์กด์žฌํ•˜๋Š”๋ฐ์š”, ์ด์— ๋Œ€ํ•ด ๊ฐ„๋žตํžˆ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

 

 

๐Ÿ’ป Log4j


 Apache Log4j ๋Š” ๋‹ค๋ฅธ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ์— ๋น„ํ•ด ์•„ํŒŒ์น˜ ์žฌ๋‹จ์˜ ๊ฐ€์žฅ ์˜ค๋ž˜๋œ ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค. ์ฝ˜์†” ๋ฐ ํŒŒ์ผ ์ถœ๋ ฅ์˜ ํ˜•ํƒœ๋กœ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ์œผ๋ฉฐ, xml์ด๋‚˜ properties ํ™˜๊ฒฝ์œผ๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.  Apache ๊ณต์‹๋ฌธ์„œ์—์„œ๋Š” 2015๋…„ 8์›”์„ ๋์œผ๋กœ Log4j๋Š” ๊ฐœ๋ฐœ์ด ์ค‘๋‹จ๋˜์—ˆ์œผ๋ฉฐ, Log4j2๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ ํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

http://logging.apache.org/log4j/1.2/

Log4j๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตฌ์„ฑ ๋ฐ ๋กœ๊ทธ ๋ ˆ๋ฒจ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

Log4j ๊ตฌ์„ฑ

์š”์†Œ ์„ค๋ช…
Logger ์ถœ๋ ฅํ•  ๋ฉ”์‹œ์ง€๋ฅผ Appender์—๊ฒŒ ์ „๋‹ฌ
Appender ์ „๋‹ฌ๋œ ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•  ๋Œ€์ƒ์„ ์ง€์ •(File, Console, JDBC ๋“ฑ)
Layout ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•  ํ˜•์‹์„ ์ง€์ •

 

 

Log4j์˜ ๋กœ๊ทธ ๋ ˆ๋ฒจ

๋กœ๊ทธ ๋ ˆ๋ฒจ ์„ค๋ช…
FATAL ์•„์ฃผ ์‹ฌ๊ฐํ•œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ์ƒํƒœ. ์ผ๋ฐ˜์ ์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ์‚ฌ์šฉํ•  ์ผ์ด ์—†์Œ
ERROR ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ ์ƒํƒœ
WARN ์‹คํ–‰์—๋Š” ๋ฌธ์ œ๊ฐ€ ์—†์œผ๋‚˜ ํ–ฅํ›„ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ๊ณ ์„ฑ ๋ฉ”์‹œ์ง€
INFO ๋กœ๊ทธ์ธ, ์ƒํƒœ๋ณ€๊ฒฝ๊ณผ ๊ฐ™์€ ์ •๋ณด์„ฑ ๋ฉ”์‹œ์ง€
DEBUG ๋””๋ฒ„๊ทธ ์šฉ๋„๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์‹œ์ง€
TRACE ๋””๋ฒ„๊ทธ ๋ ˆ๋ฒจ๋ณด๋‹ค ์ƒ์„ธํ•œ ์ด๋ฒคํŠธ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฉ”์‹œ์ง€
๋กœ๊ทธ ๋ ˆ๋ฒจ์€ FATAL > ERROR > WARN > INFO > DEBUG > TRACE ์ˆœ์„œ๋ฅผ ๊ฐ€์ง€๋ฉฐ,
DEBUG์„ ๋กœ๊ทธ ๋ ˆ๋ฒจ๋กœ ์ง€์ •ํ•˜๋ฉด ์ƒ์œ„ ๋ ˆ๋ฒจ์ธ FATAL ~ DEBUG๊นŒ์ง€ ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ์ด ๋ฉ๋‹ˆ๋‹ค.

 

 

Log4j ์˜ˆ์ œ

์˜์กด์„ฑ ์ถ”๊ฐ€

// gradle
implementation group: 'log4j', name: 'log4j', version: '1.2.17'

// maven
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

 

 

resources ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์— log4j.xml ํŒŒ์ผ ์ถ”๊ฐ€(Console)

<log4j:configuration debug="false">
    <!--Console appender -->
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %m%n"/>
        </layout>
    </appender>

    <root>
        <level value="DEBUG"/>
        <appender-ref ref="stdout"/>
    </root>
</log4j:configuration>

 

 

์˜ˆ์ œ ์ฝ”๋“œ

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

public class Logging {

    private static final Logger logger = Logger.getLogger(Logging.class);

    public static void main(String[] args) {
        logger.setLevel(Level.DEBUG);

        logger.fatal("FATAL Logging");
        logger.error("ERROR Logging");
        logger.warn("WARN Logging");
        logger.info("INFO Logging");
        logger.debug("DEBUG Logging");
        logger.trace("TRACE Logging");
    }
}

 

 

โ€ป ๋‹ค์Œ๊ณผ ๊ฐ™์ด {}์— ์ธ์ž๋ฅผ ๋„ฃ์–ด์คŒ์œผ๋กœ์จ ์ถœ๋ ฅ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

// logger.info("์š”์ฒญ URL: " + request.getRequestUrl());

logger.info("์š”์ฒญ URL: {}",request.getRequestUrl());
logger.info("์š”์ฒญ ์‹œ๊ฐ„: {}",LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
logger.info("์š”์ฒญ IP: {}",request.getRemoteAddr());

String์˜ ๋”ํ•˜๊ธฐ ์—ฐ์‚ฐ(+)์„ ํ†ตํ•ด ๋ฌธ์ž์—ด์„ ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๊ณ  ์œ„์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์„ฑ๋Šฅ์ƒ์œผ๋กœ ์ด์ ์„ ๊ฐ€์ ธ๊ฐ€๊ฒŒ ๋œ๋‹ค๊ณ  ํ•˜๋‹ˆ, ์œ„์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

 

 

๐Ÿ’ป Log4j2


 Apache Log4j2 ๋Š” ์ด์ „ ๋ฒ„์ „์ธ Log4j 1.x์— ๋น„ํ•ด ์ƒ๋‹นํžˆ ๊ฐœ์„ ๋œ Log4j์˜ ์—…๊ทธ๋ ˆ์ด๋“œ ๋œ ๋ฒ„์ „์œผ๋กœ Logback ์•„ํ‚คํ…์ณ์— ๋‚ด์žฌ๋œ ๋ช‡ ๊ฐ€์ง€ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ฉด์„œ Logback์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ์ž…๋‹ˆ๋‹ค.

Logback์ฒ˜๋Ÿผ ํ•„ํ„ฐ๋ง ๊ธฐ๋Šฅ๊ณผ ์ž๋™ ๋ฆฌ๋กœ๋”ฉ์„ ์ง€์›ํ•˜๋ฉฐ, ์ฐจ์ด์ ์€ ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ ํ™˜๊ฒฝ์—์„œ ๋น„๋™๊ธฐ ๋กœ๊ฑฐ(Async Logger)๋Š” ๋‹ค๋ฅธ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๋ณด๋‹ค ์ฒ˜๋ฆฌ๋Ÿ‰์ด ํ›จ์”ฌ ๋งŽ๊ณ , ๋Œ€๊ธฐ ์‹œ๊ฐ„์ด ํ›จ์”ฌ ์งง์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ Java8์— ๋„์ž…๋œ ๋žŒ๋‹ค์‹์„ ์ง€์›ํ•˜๊ณ , Lazy Evaluation์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

 

Log4j 1.x ๋ฒ„์ „๊ณผ์˜ ์ฐจ์ด์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ์‹ ๋ขฐ์„ฑ ํ–ฅ์ƒ: Log4j 1.x์ด๋‚˜ Logback๊ณผ ๊ฐ™์ด ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์žฌ๊ตฌ์„ฑํ•˜๋Š” ๋™์•ˆ ๋ฉ”์‹œ์ง€๊ฐ€ ์†์‹ค๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค
  • ํ™•์žฅ์„ฑ: Log4j2๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ปค์Šคํ…€ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ์ •์˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ”Œ๋Ÿฌ๊ทธ์ธ ์‹œ์Šคํ…œ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • ๊ฐ„๋‹จํ•œ ๊ตฌ์„ฑ ๋ฌธ๋ฒ•
  • xml, json, yaml, properties ์†์„ฑ ์ง€์›
  • ๊ฐœ์„ ๋œ filters
  • ํ™˜๊ฒฝํŒŒ์ผ, ์‹œ์Šคํ…œ ์†์„ฑ, ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ThreadContextMap, ์ด๋ฒคํŠธ์— ์ •์˜๋œ ๊ฐ’์— ๋Œ€ํ•œ Property ์กฐํšŒ ์ง€์›
  • ๋‹ค์ค‘ API ์ง€์›: Log4j2๋Š” Log4j2, Log4j, Slf4j, Commong Logging ๋ฐ julva.util.logging(JUL) API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž ์ปค์Šคํ…€ ๋กœ๊ทธ ๋ ˆ๋ฒจ
  • "Lazy Logging"์„ ์œ„ํ•œ Java8 ์Šคํƒ€์ผ์˜ ๋žŒ๋‹ค ์ง€์›
  • ํ–ฅ์ƒ๋œ ์†๋„

 

์ถœ์ฒ˜: https://en.wikipedia.org/wiki/Log4j

 

 

 

 

๐Ÿ’ป Slf4j


 Slf4j(Simple Logging Facaed for Java) ๋Š” ์ž์ฒด์ ์ธ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์•„๋‹Œ logger์˜ ์ถ”์ƒ์ฒด๋กœ์„œ ๋‹ค๋ฅธ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ์ถ”์ƒํ™” ๊ณ„์ธต์ž…๋‹ˆ๋‹ค. ์ฆ‰, Log4j๋‚˜ Logback์™€ ๊ฐ™์€ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ธํ„ฐํŽ˜์ด์Šค ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ Slf4j๋ฅผ ์ด์šฉํ•˜๋ฉด ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๊ฐ€ ๋‹ค๋ฅธ ๊ตฌํ˜„์ฒด๋กœ ๋ณ€๊ฒฝ๋˜๋”๋ผ๋„ ์ฝ”๋“œ๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

โ€ป ์ฐธ๊ณ : ๋””์ž์ธ ํŒจํ„ด - ํผ์‚ฌ๋“œ ํŒจํ„ด(Facade Pattern)

 

์ถœ์ฒ˜: http://www.slf4j.org/manual.html

 

 

 

 

๐Ÿ’ป  Logback


 Logback ์€ Log4j๋ณด๋‹ค ํ–ฅ์ƒ๋œ ๋กœ๊น… ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ๊ฐ€์žฅ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์ „์— ์†Œ๊ฐœ๋“œ๋ฆฐ  Slf4j ์˜ ๊ตฌํ˜„์ฒด๋กœ์จ ๋™์ž‘ํ•˜๋Š” Logback์€ ์ œ๊ฐ€ ์ฃผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ์Šคํ”„๋ง๋ถ€ํŠธ์˜ ๊ฒฝ์šฐ spring-boot-starter-web ์˜์กด์„ฑ ๋‚ด๋ถ€์— logback ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ํฌํ•จ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€์ ์ธ ์„ค์ • ์—†์ด ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

Logback ์˜ˆ์ œ

์˜์กด์„ฑ ์ถ”๊ฐ€

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation('org.slf4j:jcl-over-slf4j')
implementation('ch.qos.logback:logback-classic')

 

resources ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์— logback.xml ํŒŒ์ผ ์ถ”๊ฐ€(File)

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

<configuration>

    <!-- ์ฝ˜์†”๋กœ ๋กœ๊ทธ๋ฅผ ๋‚จ๊น€ -->
    <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <charset>UTF-8</charset>
            <Pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
            </Pattern>
        </encoder>
    </appender>

    <!-- ํŒŒ์ผ๋กœ ๋กœ๊ทธ๋ฅผ ๋‚จ๊น€ -->
    <appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/Users/juhyun/Desktop/study/logback.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
            </Pattern>
        </encoder>

        <!-- ๋กœ๊ทธ ํŒŒ์ผ์ด 10KB๊ฐ€ ๋„˜์œผ๋ฉด ์ƒˆ๋กœ์šด ๋กœ๊ทธ ํŒŒ์ผ๋กœ ๋งŒ๋“œ๋Š” ์ •์ฑ… -->
        <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10KB</MaxFileSize>
        </triggeringPolicy>

        <!-- ํŒŒ์ผ์„ ๋ฎ์–ด์“ฐ๋Š” ์ •์ฑ… -->
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>/Users/juhyun/Desktop/study/logback2.%i.log.zip</FileNamePattern>
            <!--
                MinIndex, MaxIndex => ๋กœ๊ทธ ํŒŒ์ผ ์ •์ฑ…
                logback2.1.log.zip, logback2.2.log.zip, ...
            -->
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>
    </appender>

    <!-- com.juhyun ํ•˜์œ„ ํŒจํ‚ค์ง€ -->
    <logger name="com.juhyun"  level="info" additivity="false">
        <appender-ref ref="fileAppender" />
    </logger>

</configuration>

์œ„ ํŒŒ์ผ์— ๋Œ€ํ•ด ์ฃผ์„์„ ์ถ”๊ฐ€ํ–ˆ์ง€๋งŒ, ๊ฐ„๋žตํ•˜๊ฒŒ ์„ค๋ช…๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

<appender name="fileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">

  • RollingFileAppender ํด๋ž˜์Šค๋Š” FileAppender ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์œผ๋ฉฐ ๋กœ๊ทธ ํŒŒ์ผ์„ ๋กค์˜ค๋ฒ„ ํ•˜๋Šฅ ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

์ถœ์ฒ˜: http://logback.qos.ch/manual/appenders.html

 

%d{HH:mm:ss.SSS}

  • ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ์‹œ๊ฐ„์„ ๊ธฐ๋กํ•˜๋Š” ์„ค์ •์ž…๋‹ˆ๋‹ค.

 

[%thread]

  • ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ์Šค๋ ˆ๋“œ๋ฅผ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค.

 

%-5level

  • ๋กœ๊ทธ ๋ ˆ๋ฒจ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
  • -5๋Š” 5์นธ์„ ์ฐจ์ง€ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

%logger{5}

  • ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•  java ํŒŒ์ผ๋ช…์„ ๋‚˜ํƒ€๋‚ด๋ฉฐ, {5}์€ ํŒŒ์ผ๋ช…์˜ ํฌ๋งทํŒ… ํ˜•์‹์ž…๋‹ˆ๋‹ค.

 

%msg%n

  • ๋ฉ”์‹œ์ง€์™€ ๊ฐœํ–‰(์ค„๋ฐ”๊ฟˆ)์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

 

 

์˜ˆ์ œ ์ฝ”๋“œ

package com.juhyun;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Logging {
    public static void main(String[] args) {
        log.debug("Logging - Debug log");
        log.info("Logging - Info log");
        log.warn("Logging - Warn log");
        log.error("Logging - Error log");
    }
}

์œ„ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด xmlํŒŒ์ผ์— ์„ค์ •ํ•œ ๊ฒฝ๋กœ์— log ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜๋Š”๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

file์— ์ถœ๋ ฅํ•  ๋กœ๊ทธ ๋ ˆ๋ฒจ์„ info๋กœ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—, ํ•˜์œ„ ๋ ˆ๋ฒจ์ธ Debug๋Š” ์ถœ๋ ฅ์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

 

 

 

๐Ÿ“  ์ •๋ฆฌ


์ด์ƒ์œผ๋กœ ๊ฐ„๋žตํ•˜๊ฒŒ ๋กœ๊น…์— ๋Œ€ํ•ด ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๋‹ค์–‘ํ•œ ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•˜๋ฉด ํด๋ž˜์Šค๋ณ„๋กœ ๋กœ๊ทธ ํŒŒ์ผ์„ ๋‚จ๊ธฐ๊ฑฐ๋‚˜, ๋กœ๊ทธ ๋ ˆ๋ฒจ์„ ์„ค์ •ํ•˜์—ฌ ์ข€ ๋” ์ •ํ™•ํ•œ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐœ๋ฐœ์„ ํ•˜๋ฉฐ ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๊ฐ€ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธฐ๋Š” ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋กœ๊ทธ๋Š” ์ตœ๋Œ€ํ•œ ์ƒ์„ธํžˆ ํ•ด๋‹น ์˜ค๋ฅ˜์— ๋Œ€ํ•ด ๋‚จ๊ฒจ์ฃผ๋Š”๊ฒŒ ์ข‹๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

 

 

 

 

References

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€

๐Ÿ”HALO