Configure org.apache.log4j.ConsoleAppender with custom classloader

喜欢而已 提交于 2019-11-30 08:27:04

问题


I have a java class which creates a custom classloader based on javassist class loader on start up and then run the real program class. I'm getting the following error:

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a        
"org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [javassist.Loader@6f97b10a] whereas object of type 
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by 
[java.net.URLClassLoader@5b414a8d].
log4j:ERROR Could not instantiate appender named "stdout".

The problem is related to the fact that one object is created by the original classloader while the other is created by the custom one.
Is there a way to resolve this error?

Thanks in advance,
Avner


回答1:


Please try to set -Dlog4j.ignoreTCL=true, hope it helps. a simular issue about log4j




回答2:


Add log4j.ignoreTCL in maven tomcat plugin configuration as shown in below

<plugin>
   <groupId>org.apache.tomcat.maven</groupId>
   <artifactId>tomcat7-maven-plugin</artifactId>
   <version>2.1</version>
   <configuration>
      <port>${local.server.port}</port>
      <update>true</update>
      <systemProperties>
         <log4j.configurationFile>${user.dir}\conf\log4j2.xml</log4j.configurationFile>
         <log4j.ignoreTCL>true</log4j.ignoreTCL>
         <java.util.logging.manager>org.apache.logging.log4j.jul.LogManager</java.util.logging.manager>
      </systemProperties>
      <contextReloadable>true</contextReloadable>
   </configuration>
</plugin>


来源:https://stackoverflow.com/questions/12404934/configure-org-apache-log4j-consoleappender-with-custom-classloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!