码迷,mamicode.com
首页 > 其他好文 > 详细

logback 实例

时间:2017-06-06 18:31:24      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:log4j   package   app   pac   策略   append   war   thread   eve   

POM : 

        <!-- log -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.1</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency>

Class : Log

package com.xindatai.ibs.environ.util.constant;

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

public class Log {
    public static final Logger LOGGER = LoggerFactory.getLogger("ibs.log");
    
    public static final Logger DEVICE_LOGGER = LoggerFactory.getLogger("device.log");

}

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="false">
    <!-- Console -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern> -->
            <pattern>[%-5level %d{yyyy-MM-dd HH:mm:ss} %c{0}] - %m%n</pattern>
        </encoder>
    </appender>

    <appender name="ibs.log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.base}/logs/ibs.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${catalina.base}/logs/ibs.%d.gz</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5level %d{yyyy-MM-dd HH:mm:ss} %c{0}] - %m%n</pattern>
        </encoder>
    </appender>

    <appender name="device.log" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.base}/logs/device.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${catalina.base}/logs/device.%d.gz</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5level %d{yyyy-MM-dd HH:mm:ss} %c{0}] - %m%n</pattern>
        </encoder>
    </appender>

    <logger name="device" additivity="false">
        <appender-ref ref="device.log" />
    </logger>

    <logger name="ibs.log" additivity="false">
        <appender-ref ref="ibs.log" />
    </logger>

    <root level="INFO">
        <appender-ref ref="console" />
    </root>
</configuration>

Class : 

Log.LOGGER.warn("从picker获取环境检测及控制设备的信息:" + new Date() + "--开始搜集");

Log.DEVICE_LOGGER.warn("执行营业时间空调及净化器策略--Start");

File : 

技术分享

啦啦啦

啦啦啦

logback 实例

标签:log4j   package   app   pac   策略   append   war   thread   eve   

原文地址:http://www.cnblogs.com/ClassNotFoundException/p/6952456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!