wohuozheng
vvvvip用户
2018-01-09 03:55

log4j的使用问题,输出我想要的内容

5
  • log4j

今天想试用一下这个东西,发现

  @RequestMapping("/error")
    public String error(){
        try{
            int a=7/0;
        }catch(Exception e){
            logger.debug ( "++++++++++++++++++++++++++++++++++++++++ ") ;  
            logger.info ( "_________________________________________" ) ;  
            logger.warn ( "*******************************************") ;  
            logger.error ( "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ;
        }
        return "";
    }

上面的logger.都没有输出在文件中,其中log4j.properties的属性如下

 log4j.rootLogger =debug,stdout,D,E

log4j.appender.stdout = org.apache.log4j.ConsoleAppender  
log4j.appender.stdout.Target = System.out  
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n  

log4j.appender.D = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.D.File = D://logs/log.log  
log4j.appender.D.Append = true  
log4j.appender.D.Threshold = DEBUG   
log4j.appender.D.layout = org.apache.log4j.PatternLayout  
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n  

log4j.appender.E = org.apache.log4j.DailyRollingFileAppender  
log4j.appender.E.File =D://logs/error.log   
log4j.appender.E.Append = true  
log4j.appender.E.Threshold = ERROR   
log4j.appender.E.layout = org.apache.log4j.PatternLayout  
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

或者说我怎么能够只让他输出我想要的例如
logger.error("错误");
就是只在error.log中输出 错误 二字就好了

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

9条回答

为你推荐

换一换