Раньше я использовал log4j 1.2, и недавно я перешел на log4j 2.0. Я использовал ниже класс слушателя в log4j 1.2 в сети. xml
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Этот класс слушателя удаляется после log4j 2.0 и я требуется замена этого класса прослушивателя, который позволяет мне изменять уровень регистратора во время выполнения и обновлять без перезапуска службы tomcat в моем веб-приложении.
Я пробовал ниже прослушивателя, но это также перезапускает tomcat при изменении конфигурации в log4j2. xml
<listener>
<listener-class>org.apache.logging.log4j.core.web.Log4jContextListener</listener-class>
</listener>
Я вижу ниже Исключения и предупреждения при изменении log4j2. xml, а затем он перезапускает tomcat:
WARNING: The web application [demo] appears to have started a thread named [pool-UCCAdminMonitor-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
Jul 14, 2020 8:36:25 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
Exception in thread "Log4j2-TF-10-ConfiguratonFileWatcher-19" java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.parsers.DocumentBuilderFactory]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1385)
at org.apache.catalina.loader.WebappClassLoaderBase.findResources(WebappClassLoaderBase.java:985)
at org.apache.catalina.loader.WebappClassLoaderBase.getResources(WebappClassLoaderBase.java:1086)
at java.util.ServiceLoader$LazyIterator.hasNextService(Unknown Source)
at java.util.ServiceLoader$LazyIterator.hasNext(Unknown Source)
at java.util.ServiceLoader$1.hasNext(Unknown Source)
at javax.xml.parsers.FactoryFinder$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.parsers.FactoryFinder.findServiceProvider(Unknown Source)
at javax.xml.parsers.FactoryFinder.find(Unknown Source)
at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:183)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:89)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.reconfigure(XmlConfiguration.java:272)
at org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:752)
at org.apache.logging.log4j.core.util.AbstractWatcher$ReconfigurationRunnable.run(AbstractWatcher.java:92)
at java.lang.Thread.run(Unknown Source)
INFO: Illegal access: this web application instance has been stopped already. Could not load [org.apache.logging.log4j.core.lookup.JndiLookup]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [org.apache.logging.log4j.core.lookup.JndiLookup]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1385)
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForClassLoading(WebappClassLoaderBase.java:1373)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1226)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:167)
at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:209)
at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:230)
at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:112)
at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:129)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:76)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.reconfigure(XmlConfiguration.java:272)
at org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:752)
at org.apache.logging.log4j.core.util.AbstractWatcher$ReconfigurationRunnable.run(AbstractWatcher.java:92)