๊ด€๋ฆฌ ๋ฉ”๋‰ด

Tech Log ๐Ÿ› ๏ธ

๋กœ๊น… ํ†บ์•„๋ณด๊ธฐ ๋ณธ๋ฌธ

์Šคํ”„๋ง mvc

๋กœ๊น… ํ†บ์•„๋ณด๊ธฐ

sehaan 2022. 3. 12. 21:33

์‹ค๋ฌด์—์„œ๋Š” printLn ์ด ์•„๋‹Œ ๋กœ๊น…์„ ํ†ตํ•˜์—ฌ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ด์•ผํ•œ๋‹ค.

 


@RestController
public class LogTestController {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @RequestMapping("/log-test")
    public String logTest(){
        String name = "spring";

        log.trace("trace log = {}", name);
        log.debug("debug log = {}", name);
        log.info("info log = {}", name);
        log.warn("warn log = {}", name);
        log.error("error log = {}", name);

        log.debug("debug log={}",name);

        return "ok";
        
    }

 

๋จผ์ € ํด๋ž˜์Šค ๋ ˆ๋ฒจ์— ๋ถ™์€ @RestController ์—๋…ธํ…Œ์ด์…˜์€ ๋ฆฌํ„ด ๊ฐ’์„ Http ๋ฐ”๋””์— ๋ฐ”๋กœ ์ž…๋ ฅํ•ด์ค€๋‹ค.

(@Controller ๋Š” ๋ฐ˜ํ™˜๊ฐ’์„ ๋ทฐ ์ด๋ฆ„์œผ๋กœ ์ธ์‹ํ•œ๋‹ค.)

 

@Slf4j
@RestController
public class LogTestController {
    //private final Logger log = LoggerFactory.getLogger(getClass());

๋˜ํ•œ @sLf4j ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ๋กœ๊ทธ ์„ ์–ธ์„ ํ•ด์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

 

๋กœ๊ทธ๋ฅผ ๋ณด๋ฉด trace์™€ debug ๋กœ๊ทธ๊ฐ€ ์ฐํžˆ์ง€ ์•Š์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š” ๋ฐ, ์ด๋Š” application.properties ์˜ ๊ธฐ๋ณธ ์„ค์ •๊ณผ ๊ด€๋ จ์ด ์žˆ๋‹ค.

 

# ๊ธฐ๋ณธ ์„ค์ •
logging.level.root=info
#debug ์ดํ•˜์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•ด์ค€๋‹ค.
logging.level.hello.springmvc=debug

 

์ด๋ ‡๊ฒŒ ์„ค์ •์„ ํ•˜๊ณ  ๋‹ค์‹œ ๋กœ๊ทธ๋ฅผ ์ฐ์–ด๋ณด์ž

 

์ด๋Ÿฐ์‹์œผ๋กœ ๋กœ๊ทธ ์ถœ๋ ฅ ๋‹จ๊ณ„๋ฅผ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋‹ค.

(TRACE > DEBUG > INFO > WARN > ERROR)

 

log.debug("debug log={}"+name);

์ฐธ๊ณ ๋กœ ์ด์™€ ๊ฐ™์€ ์ถœ๋ ฅ ํ˜•์‹์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

์ถœ๋ ฅ ์—ฌ๋ถ€์™€ ๊ด€๊ณ„์—†์ด ๋ฌธ์ž์—ด + ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ ๋‚ญ๋น„๊ฐ€ ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

๋” ๋งŽ์€ ๊ธฐ๋Šฅ์€?

SLF4J

 

SLF4J

Simple Logging Facade for Java (SLF4J) The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framewor

www.slf4j.org

Logback Home (qos.ch)

 

Logback Home

Logback Project Logback is intended as a successor to the popular log4j project, picking up where log4j 1.x leaves off. Logback's architecture is quite generic so as to apply under different circumstances. At present time, logback is divided into three mod

logback.qos.ch

Core Features (spring.io)

 

Core Features

Spring Boot lets you externalize your configuration so that you can work with the same application code in different environments. You can use a variety of external configuration sources, include Java properties files, YAML files, environment variables, an

docs.spring.io