Log:日志工具输出log的使用

  日志的简单使用,三种方式。

  1. org.apache.commons.logging.Log
    1
    2
    3
    4
    5
    //import org.apache.commons.logging.Log;
    //import org.apache.commons.logging.LogFactory;
    private static final Log log = LogFactory.getLog(xxxServiceImpl.class);

    log.info(Object msg);
  2. log4j 1.x 版本:org.apache.log4j.Logger
    1
    2
    3
    4
    //org.apache.log4j.Logger;
    private final Logger logger = Logger.getLogger(this.getClass());

    logger.info(Object msg);
  3. log4j 2.x 版本:org.apache.logging.log4j.Logger
    1
    2
    3
    private static final Logger logger = LogManager.getLogger(xxxClass.class);

    logger.info(String msg);

示例:创建一个基本服务类,里面放有Logger对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 创建一个基本Service类,存放Logger对象,
* 基它业务类继承可直接拿来用
* @author Rocky
*
*/
public class BaseService {

/**
* 日志对象
*/
protected Logger logger = LoggerFactory.getLogger(getClass());

}

Log:日志工具输出log的使用

http://blog.gxitsky.com/2018/01/21/Log-outputMethod/

作者

光星

发布于

2018-01-21

更新于

2022-06-17

许可协议

评论