记录日志

2019-11-08 11:34:00 浏览数 (1)

日志级别:debug<info<warn<error

application.yml配置日志

代码语言:javascript复制
logging:
  file: target/app.log
  level:
    ROOT: WARN
    cn.devmar: TRACE 
代码语言:javascript复制
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SampleClass{
    private static final Log log = LogFactory.getLog(TvSeriesController.class);

    public void print(String name){
        if (log.isTraceEnabled()){
        log.trace("getAll();被调用了");
    }
        try{
            //do something
        }catch(Exception e){
            if(log.isErrorEnabled()){
                log.error("出错了",e);
            }
        }
    }
}

0 人点赞