2016-05-03 33 views
0

我使用了log4j2記錄器的正確的(de)-registration的log4j-web依賴於tomcat環境:如何在log4j-web上使用WebLookup?

<dependency> 
    <groupId>org.apache.logging.log4j</groupId> 
    <artifactId>log4j-web</artifactId> 
</dependency> 

問題:那我不能用WebLookup瞭如下:

<RollingRandomAccessFile name="TEST" fileName="${web:rootDir}-${web:majorVersion}-application.log" ..> 

當我排除log4j-web依賴項時,weblookup可以正常工作。但我必須使用依賴關係進行適當的Tomcat日誌記錄。

可能是查詢初始化得太晚。 那麼,我該如何使用weblookup呢?

回答

1

一種可能的解決方案:記錄器初始化前鉤中,並填充在地圖PARAMS在log4j2.xml配置以使用:

@SpringBootApplication 
public class App extends SpringBootServletInitializer { 
    @Override 
    public void onStartup(ServletContext servletContext) throws ServletException { 
     MainMapLookup.setMainArguments(new String[] {"thekey", "thevalue"}); 
     super.onStartup(servletContext); 
    } 
} 

用法:

fileName="${main:thekey}-..."