Initialize JMXFetch if configured log manager is on sys classpath
Some applications set java.util.logging.manager but never actually initialize the logger. Check to see if the configured manager is on the system classpath. If so, it should be safe to initialize jmxfetch which will setup the log manager.
This commit is contained in:
parent
b58ec1b4fe
commit
f7abb2ac04
|
@ -243,32 +243,51 @@ public class TracingAgent {
|
||||||
* @return true if we detect a custom log manager being used.
|
* @return true if we detect a custom log manager being used.
|
||||||
*/
|
*/
|
||||||
private static boolean isAppUsingCustomLogManager() {
|
private static boolean isAppUsingCustomLogManager() {
|
||||||
|
final boolean debugEnabled =
|
||||||
|
"debug".equalsIgnoreCase(System.getProperty("datadog.slf4j.simpleLogger.defaultLogLevel"));
|
||||||
|
|
||||||
final String tracerCustomLogManSysprop = "dd.app.customlogmanager";
|
final String tracerCustomLogManSysprop = "dd.app.customlogmanager";
|
||||||
final String customLogManagerProp = System.getProperty(tracerCustomLogManSysprop);
|
final String customLogManagerProp = System.getProperty(tracerCustomLogManSysprop);
|
||||||
final String customLogManagerEnv =
|
final String customLogManagerEnv =
|
||||||
System.getenv(tracerCustomLogManSysprop.replace('.', '_').toUpperCase());
|
System.getenv(tracerCustomLogManSysprop.replace('.', '_').toUpperCase());
|
||||||
|
|
||||||
if ("debug"
|
if (customLogManagerProp != null || customLogManagerEnv != null) {
|
||||||
.equalsIgnoreCase(System.getProperty("datadog.slf4j.simpleLogger.defaultLogLevel"))) {
|
if (debugEnabled) {
|
||||||
System.out.println(
|
System.out.println("Prop - customlogmanager: " + customLogManagerProp);
|
||||||
"Prop - logging.manager: " + System.getProperty("java.util.logging.manager"));
|
System.out.println("Env - customlogmanager: " + customLogManagerEnv);
|
||||||
System.out.println("Prop - customlogmanager: " + customLogManagerProp);
|
}
|
||||||
System.out.println("Env - customlogmanager: " + customLogManagerEnv);
|
// Allow setting to skip these automatic checks:
|
||||||
System.out.println("ENV - jboss: " + System.getenv("JBOSS_HOME"));
|
return Boolean.parseBoolean(customLogManagerProp)
|
||||||
|
|| Boolean.parseBoolean(customLogManagerEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return System.getProperty("java.util.logging.manager") != null
|
final String jbossHome = System.getenv("JBOSS_HOME");
|
||||||
|| Boolean.parseBoolean(customLogManagerProp)
|
if (jbossHome != null) {
|
||||||
|| Boolean.parseBoolean(customLogManagerEnv)
|
if (debugEnabled) {
|
||||||
// Allow setting to skip these automatic checks:
|
System.out.println("Env - jboss: " + jbossHome);
|
||||||
|| ((customLogManagerProp == null && customLogManagerEnv == null)
|
}
|
||||||
&& (
|
// JBoss/Wildfly is known to set a custom log manager after startup.
|
||||||
// JBoss/Wildfly is known to set a custom log manager
|
// Originally we were checking for the presence of a jboss class,
|
||||||
// Originally we were checking for the presence of a jboss class,
|
// but it seems some non-jboss applications have jboss classes on the classpath.
|
||||||
// but it turns out other non-jboss applications have jboss classes on the classpath.
|
// This would cause jmxfetch initialization to be delayed indefinitely.
|
||||||
// This would cause jmxfetch initialization to be delayed indefinitely.
|
// Checking for an environment variable required by jboss instead.
|
||||||
// Checking for an environment variable required by jboss instead.
|
return true;
|
||||||
System.getenv("JBOSS_HOME") != null));
|
}
|
||||||
|
|
||||||
|
final String logManagerProp = System.getProperty("java.util.logging.manager");
|
||||||
|
if (logManagerProp != null) {
|
||||||
|
final boolean onSysClasspath = ClassLoader.getSystemResource(logManagerProp) == null;
|
||||||
|
if (debugEnabled) {
|
||||||
|
System.out.println("Prop - logging.manager: " + logManagerProp);
|
||||||
|
System.out.println("logging.manager on system classpath: " + onSysClasspath);
|
||||||
|
}
|
||||||
|
// Some applications set java.util.logging.manager but never actually initialize the logger.
|
||||||
|
// Check to see if the configured manager is on the system classpath.
|
||||||
|
// If so, it should be safe to initialize jmxfetch which will setup the log manager.
|
||||||
|
return !onSysClasspath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue