Logback(第一章)

Logback官方网站

引入jar包

不多解释logback引用slf4j,同log4j一样重写了slf4j。logback的性能要强于log4j。

        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>${slf4j.version}version>
        dependency>
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-coreartifactId>
            <version>${logback.version}version>
        dependency>
        <dependency>
            <groupId>ch.qos.logbackgroupId>
            <artifactId>logback-classicartifactId>
            <version>${logback.version}version>
        dependency>

基础输出

/**
 * @program: myspringboot
 * @description:
 * @author: Mr.Jangni
 * @create: 2018-05-24 20:58
 **/
public class LogBack {
    public static void main(String[] args){
        Logger logger = (Logger) LoggerFactory.getLogger("biz");
        logger.setLevel(Level.INFO);
        logger.trace("trace");
        logger.debug("debug");
        logger.info("info");
        logger.warn("warn");
        logger.error("error");

        Logger loggersql = (Logger) LoggerFactory.getLogger("sql");
        loggersql.setLevel(Level.WARN);
        loggersql.warn("select * from table");

    }
}
//输出 根据等级不同输出也不相同,注意观察biz和sql
2018-05-24 21:14:32.366 [main] INFO  biz - info
2018-05-24 21:14:32.369 [main] WARN  biz - warn
2018-05-24 21:14:32.369 [main] ERROR biz - error
2018-05-24 21:14:32.369 [main] WARN  sql - select * from table

你可能感兴趣的:(日志,logback)