Logback初次尝试体验

package com.czie.iot1913;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * FileName: Test
 * Author:   lps
 * Date:     2022/4/16 15:27
 * Sign:刘品水 Q:1944900433
 * 目的:快速搭建logback日志框架 记录程序的执行情况 到控制台 到文件夹中
 * public static final Logger LOGGER=LoggerFactory.getLogger("类对象");
 */
public class Test {
    //创建Logback的日志对象 代表日志技术

     public static final Logger LOGGER=LoggerFactory.getLogger("Test.class");
    public static void main(String[] args) {
        try {
            LOGGER.debug("main方法开始执行");
            LOGGER.info("我开始记录第二行日志,我要开始吹牛咯哈哈嗨");
            int a=10;
            int b=0;
            LOGGER.trace("a="+a);
            LOGGER.trace("b="+b);
            System.out.println(a/b);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("功能出现异常为:"+e);
        }

    }
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">

<!--日志输入到控制台-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<!--<appender name="permission" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
<!--<file>${catalina.home}/logs/permission.log</file>-->
<!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
<!--<FileNamePattern>${catalina.home}/logs/permission.%d{yyyy-MM-dd}.log.gz</FileNamePattern>-->
<!--</rollingPolicy>-->
<!--<layout class="ch.qos.logback.classic.PatternLayout">-->
<!--<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>-->
<!--</layout>-->
<!--</appender>-->
<!---->
<!--<logger name="xxx" level="INFO">-->
<!--<appender-ref ref="permission"/>-->
<!--</logger>-->

<!-- TRACE < DEBUG < INFO < WARN < ERROR -->
<root level="all">
<appender-ref ref="STDOUT" />
</root>

</configuration>

 

 

posted @ 2022-04-17 13:16  刘品水  阅读(18)  评论(0编辑  收藏  举报