标准logback.xml日志模版,拿去就用,别整那些花里胡哨的


<configuration debug="false" scan="true">
    <property name="baseDir" value="logs"/>
    <property name="maxHistory" value="30"/>
    <property name="maxFileSize" value="100MB"/>
    <property name="logPatten" value="%date{yyyy-MM-dd HH:mm:ss}|%-5level|%thread|%file:%line|%logger|%msg%n"/>

    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%yellow(%date{yyyy-MM-dd HH:mm:ss})|%highlight(%-5level)|%blue(%thread)|%blue(%file:%line)|%green(%logger)|%cyan(%msg%n)pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>trancelevel>
        filter>
    appender>

    <appender name="trace" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${baseDir}/trace/%d{yyyy-MM-dd}/%d{yyyy-MM-dd_HH}-%i.logFileNamePattern>
            <MaxHistory>${maxHistory}MaxHistory>
            <maxFileSize>${maxFileSize}maxFileSize>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logPatten}pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>tracelevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${baseDir}/debug/%d{yyyy-MM-dd}/%d{yyyy-MM-dd_HH}-%i.logFileNamePattern>
            <MaxHistory>${maxHistory}MaxHistory>
            <maxFileSize>${maxFileSize}maxFileSize>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logPatten}pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>debuglevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${baseDir}/info/%d{yyyy-MM-dd}/%d{yyyy-MM-dd_HH}-%i.logFileNamePattern>
            <MaxHistory>${maxHistory}MaxHistory>
            <maxFileSize>${maxFileSize}maxFileSize>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logPatten}pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>infolevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${baseDir}/warn/%d{yyyy-MM-dd}/%d{yyyy-MM-dd_HH}-%i.logFileNamePattern>
            <MaxHistory>${maxHistory}MaxHistory>
            <maxFileSize>${maxFileSize}maxFileSize>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logPatten}pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>warnlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <FileNamePattern>${baseDir}/error/%d{yyyy-MM-dd}/%d{yyyy-MM-dd_HH}-%i.logFileNamePattern>
            <MaxHistory>${maxHistory}MaxHistory>
            <maxFileSize>${maxFileSize}maxFileSize>
        rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logPatten}pattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>errorlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <root level="error">
        <appender-ref ref="stdout"/>
        <appender-ref ref="trace"/>
        <appender-ref ref="debug"/>
        <appender-ref ref="info"/>
        <appender-ref ref="warn"/>
        <appender-ref ref="error"/>
    root>

    <logger name="com.wxy" level="debug"/>

configuration>

你可能感兴趣的:(java基础,logback,java)