2016-02-07 73 views
1

我開始在我正在開發的系統上使用Log4j2。 而我遇到了一些問題。Log4j2滾動文件不工作

這裏是我的log4j2.properties文件。

status = error 
name = PropertiesConfig 

filters = threshold 

filter.threshold.type = ThresholdFilter 
filter.threshold.level = debug 

appenders = console, rolling, list 

appender.console.type = Console 
appender.console.name = STDOUT 
appender.console.layout.type = PatternLayout 
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 

appender.rolling.type = RollingFile 
appender.rolling.name = RollingFile 
appender.rolling.fileName = ${sys:catalina.home}/logs/beo.log 
appender.rolling.filePattern = ${sys:catalina.home}/logs/beo-%d{MM-dd-yy-HH-mm-ss}-%i.log 
appender.rolling.layout.type = PatternLayout 
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n 
appender.rolling.policies.type = Policies 
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
appender.rolling.policies.time.interval = 2 
appender.rolling.policies.time.modulate = true 
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size=100MB 
appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.max = 5 

appender.list.type = List 
appender.list.name = List 
appender.list.filters = threshold 
appender.list.filter.threshold.type = ThresholdFilter 
appender.list.filter.threshold.level = error 

loggers = rolling 

logger.rolling.name = org.apache.logging.log4j.core.appender.rolling 
logger.rolling.level = debug 
logger.rolling.additivity = false 
logger.rolling.appenderRefs = rolling 
logger.rolling.appenderRef.rolling.ref = RollingFile 

rootLogger.level = info 
rootLogger.appenderRefs = stdout 
rootLogger.appenderRef.stdout.ref = STDOUT 

這裏是登錄方法其中i試圖測試記錄。

private static final Logger LOGGER = LogManager 
      .getLogger(NavigationController.class.getName()); 

@RequestMapping(value = { "/", "/login" }) 
    public ModelAndView loginPage(
      @RequestParam(value = "error", required = false) String error, 
      @RequestParam(value = "logout", required = false) String logout) { 

     ModelAndView mv = new ModelAndView(); 

     Authentication auth = SecurityContextHolder.getContext() 
       .getAuthentication(); 

     if (!(auth instanceof AnonymousAuthenticationToken)) { 
      mv.setViewName("redirect:/auth/panel"); 

     } else { 
      if (error != null) { 
       mv.addObject("error", "Invalid username and password!"); 
       LOGGER.debug("debug"); 
       LOGGER.info("info"); 
       LOGGER.error("error"); 
       LOGGER.warn("warning"); 
       LOGGER.fatal("fatal"); 
      } 
      mv.setViewName("login"); 
     } 

     return mv; 
    } 

enter image description here

的RollingFile似乎並沒有工作。它創建一個名爲beo.logs的日誌文件,但它也是空的。我的配置有問題嗎?

回答

2

您的記錄器名稱顯示爲somepackage.NavigationController。它所在的軟件包當然不是org.apache.logging.log4j.core.appender.rolling,它是您配置到RollingFileAppender的唯一Logger。我懷疑你真的想使用NavigationController的包名稱。

+0

非常感謝! – pat3ck029