Merge pull request #1197 from AM-19/branch2

[AMQ-9470] Updated Methods to be called, to properly reload Log4j Properties
This commit is contained in:
JB Onofré 2024-04-10 22:31:04 +02:00 committed by GitHub
commit 04e84afa89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 20 deletions

View File

@ -216,26 +216,11 @@ public class Log4JConfigView implements Log4JConfigViewMBean {
return;
}
Method resetConfiguration = logManagerClass.getMethod("resetConfiguration", new Class[]{});
resetConfiguration.invoke(null, new Object[]{});
Method getContext = logManagerClass.getMethod("getContext", boolean.class);
Object logContext = getContext.invoke(logManagerClass, false);
Method reconfigure = logContext.getClass().getMethod("reconfigure");
reconfigure.invoke(logContext);
String configurationOptionStr = System.getProperty("log4j.configuration");
URL log4jprops = null;
if (configurationOptionStr != null) {
try {
log4jprops = new URL(configurationOptionStr);
} catch (MalformedURLException ex) {
log4jprops = cl.getResource("log4j.properties");
}
} else {
log4jprops = cl.getResource("log4j.properties");
}
if (log4jprops != null) {
Class<?> propertyConfiguratorClass = cl.loadClass("org.apache.log4j.PropertyConfigurator");
Method configure = propertyConfiguratorClass.getMethod("configure", new Class[]{URL.class});
configure.invoke(null, new Object[]{log4jprops});
}
} catch (InvocationTargetException e) {
throw e.getTargetException();
}