SLF4J+LogBack用法

依赖

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.26</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>

基本用法

/**
 * @author blog.unclezs.com
 * @date 2020/12/1 10:46 下午
 */
public class LogbackSample {
    static final Logger logger = LoggerFactory.getLogger(LogbackSample.class);

    public static void main(String[] args) {
        logger.info("log by Logback");
        logger.warn("log by Logback");
        logger.error("log by Logback");
        logger.debug("log by Logback");
        logger.trace("log by Logback");
    }
}

如何配置logback.xml

Logback 配置官方文档

Common-Logging+Log4J的用法

依赖

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.14.0</version>
</dependency>

基本用法

/**
 * @author blog.unclezs.com
 * @date 2020/12/1 10:50 下午
 */
public class Log4jSample {
    public static void main(String[] args) {
        Logger logger = LogManager.getLogger(Log4jSample.class);
        logger.info("log by log4j2");
        logger.warn("log by log4j2");
        logger.error("log by log4j2");
        logger.debug("log by log4j2");
        logger.trace("log by log4j2");
    }
}

配置log4j2.xml

博客
分类
标签
归档
关于