Java日志:笔记 sl4j

1.Slf4j 

1.1 Maven   pom.xml

 <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
      </dependency>
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
      </dependency>

1.2  测试

package com.test;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

 

public class Main {

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

    public static void main(String[] args) {

        int status = 0;

        if (status == 0) {

            logger.info("status:{}", status);

        } else {

            logger.info("status:{}", status);

        }

        logger.info("end!");
        logger.debug("debug");
        logger.debug("debug","msg"+Thread.currentThread());
        logger.error("error","error_msg");

    }

}

1.3 输出结果

18:16:42.728 [main] INFO com.test.Main - status:0
18:16:42.735 [main] INFO com.test.Main - end!
18:16:42.735 [main] DEBUG com.test.Main - debug
18:16:42.735 [main] DEBUG com.test.Main - debug
18:16:42.735 [main] ERROR com.test.Main - error

1.3占位符:

      logger.debug("Processing trade with id: {} and symbol : {} ", test_id, symbol);

1.3.1输出结果:

18:29:38.340 [main] DEBUG com.test.Main - Processing trade with id: 123456 and symbol : ssss 
发布了221 篇原创文章 · 获赞 8 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/oDianZi1234567/article/details/103994123
今日推荐