Log4j 설정파일 위치 지정하기 Java/Servlet2014. 3. 14. 23:52
log4j.xml 또는 log4j.properties파일은 classes폴더에 있으면, 자동으로 읽어오지만...
굳이 classes가 아닌 다른 곳에 위치하고 싶은 경우는 web.xml에 Log4jConfigListener를 등록하여 사용한다.
1
2
3
4
5
6
7
8 |
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param> |
만약... 설정한뒤에 다음과 같은 에러가 뜬다면...
Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [C:\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\wtpwebapps\SpringMVCProject\] instead of [C:\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\wtpwebapps\SpringMVCProject2\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:148)
at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
at org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
만약 하나의 톰캣에 context가 여러개이고... 각각의 context가 Log4jConfigListener를 사용했을경우에 webAppRootKey가 동일하기때문에 발생하는 에러다. 그때는 webAppRootKey를 추가하여 각각의 context마다 다르게 param-value를 지정하면 해결된다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.spring1</param-value>
</context-param> |
'Java > Servlet' 카테고리의 다른 글
web.xml 에러 페이지 설정 (1) | 2018.07.25 |
---|---|
Spring MVC Controller에서 ServletContext 사용하기 (0) | 2017.09.21 |
JSTL loop (0) | 2014.03.14 |
Servlet Filter에서 Spring Bean 사용 (1) | 2014.03.14 |
인터넷 익스플로러 호환성보기 모드 서버에서 해제 (0) | 2014.03.11 |