idea控制台日志打印

idea控制台日志打印

1.添加依赖`

<!-- 控制台日志打印-->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>

2.在resource目录下创建logback-spring.xml 文件
idea控制台日志打印_第1张图片
3.文件中的内容为:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<!-- scan,当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
<!-- scanPeriod,设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟 -->
<!-- debug,当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false -->
<configuration debug="false" scan="true" scanPeriod="60000">
    <!-- contextName ,设置日志上下文名称,可以通过%contextName来打印日志上下文名称 -->
    <contextName>mq</contextName>

    <!-- property可以用来设置变量 name,用于${name}访问的key value,用于${name}访问的value
    <property name="log.path" value="F:\\logback.log" />-->

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>.%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg %n
            </Pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
    </appender>

    <appender name="info-file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- 每天一归档 -->
            <fileNamePattern>logs/mq-info.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <!-- 单个日志文件最多 10MB, 90天的日志周期,最大不能超过20GB -->
            <maxFileSize>10MB</maxFileSize>
            <totalSizeCap>20GB</totalSizeCap>
            <maxHistory>90</maxHistory>
        </rollingPolicy>
        <encoder>
            <Pattern>.%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg %n
            </Pattern>
            <charset>UTF-8</charset>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- LevelFilter: 级别过滤器,根据日志级别进行过滤 -->
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <appender name="error-file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- 每天一归档 -->
            <fileNamePattern>logs/mq-error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <!-- 单个日志文件最多 10MB, 90天的日志周期,最大不能超过100GB -->
            <maxFileSize>10MB</maxFileSize>
            <totalSizeCap>20GB</totalSizeCap>
            <maxHistory>90</maxHistory>
        </rollingPolicy>
        <encoder>
            <Pattern>.%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg %n
            </Pattern>
            <charset>UTF-8</charset>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- LevelFilter: 级别过滤器,根据日志级别进行过滤 -->
            <level>ERROR</level>
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <root>
        <!-- Log Level — ERROR, WARN, INFO, DEBUG or TRACE. -->
        <level value="INFO"/>
        <appender-ref ref="console"/>
        <appender-ref ref="info-file"/>
        <appender-ref ref="error-file"/>
    </root>

    <!-- <logger name="com.futreprocessing.spring" level="INFO" /> -->
</configuration>

你可能感兴趣的:(java,intellij,idea)