首页 > 代码库 > logback配置

logback配置

import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class MyApp {    final static Logger logger = LoggerFactory.getLogger("MyApp.class");    public static void main(String[] args) {        logger.trace("trace");        logger.debug("debug");        logger.info("info");        logger.warn("warn");        logger.error("error");        System.out.println(111);    }}
<configuration>    <property name="LOG_FORMAT" value=http://www.mamicode.com/"%date [%thread] %-5level %logger - %msg%n%rEx" />    <property name="CHARSET" value=http://www.mamicode.com/"UTF-8" />    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">//输出到控制台        <encoder>            <pattern>%date [%thread] %-5level (%file:%line\) - %msg%n</pattern>//输出格式            <charset>${CHARSET}</charset>        </encoder>    </appender>    <appender name="file—info"        class="ch.qos.logback.core.rolling.RollingFileAppender">//输出到文件        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">            <FileNamePattern>D:/logs/info.%d{yyyy-MM-dd}.log</FileNamePattern>            <MaxHistory>30</MaxHistory>        </rollingPolicy>        <encoder>            <pattern>%date [%thread] %-5level (%file:%line\) - %msg%n</pattern>            <charset>${CHARSET}</charset>        </encoder>    </appender>    <root level="info">        <appender-ref ref="stdout" />        <appender-ref ref="file—info" />    </root></configuration>