Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
I am trying to configure log4j2 to access the loggers via JMX and change their log levels.
There are two operations that are available via LoggerContext in JConsole.
1. getConfigText
2. setConfigText
The problem is with the first one. According to the documentation:
getConfigText returns the configuration text, which may be
1. The contents of the configuration file.
2. The text that was last set with a call to setConfigText.
The problem is that getConfigText works fine with second statement but its not working with the first one. Which means if you try to get the configuration text without first setting it with the setConfigText, you will see the exception instead. The following one:
java.io.FileNotFoundException: /usr/local/Cellar/tomcat/7.0.47/libexec/bin/Erex (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at java.io.FileInputStream.<init>(FileInputStream.java:101) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:90) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:188) at java.net.URL.openStream(URL.java:1037) at org.apache.logging.log4j.core.jmx.LoggerContextAdmin.readContents(LoggerContextAdmin.java:203) at org.apache.logging.log4j.core.jmx.LoggerContextAdmin.getConfigText(LoggerContextAdmin.java:161) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75) at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279) at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:112) at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:46) at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237) at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138) at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420) at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) at sun.reflect.GeneratedMethodAccessor171.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) at sun.rmi.transport.Transport$1.run(Transport.java:177) at sun.rmi.transport.Transport$1.run(Transport.java:174) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:173) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670) 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:744)
I have set the configuration file path as a part of VM parameters like that:
-Dlog4j.configurationFile=file:/Users/mansoor.sajjad/ErexLogs/exchange/conf/log4j2.xml
But the exception logs showing that its trying to get the path from within tomcat /usr/local/Cellar/tomcat/7.0.47/libexec/bin/Erex
My findings:
Debugging through the code I have found the configLocation inside the LoggerContext is always null. Due to which the LoggerContextAdmin creates the path using the ConfigName in the current path. ConfigName in my case is Erex that and the current path is obviously the tomcat.
So i get the path "/usr/local/Cellar/tomcat/7.0.47/libexec/bin/Erex", which is wrong.
Why the configLocation inside the LogerContext is always null?
Attachments
Issue Links
- duplicates
-
LOG4J2-539 IllegalArgumentException after editing config, pressing "Reconfigure using XML below"
- Resolved
- relates to
-
LOG4J2-2770 NullPointerException after reconfiguring via JMX
- Resolved