From 384e2b227ca3fa07d8a8261d0ef80360c47b396f Mon Sep 17 00:00:00 2001 From: tbradellis Date: Wed, 22 Jun 2022 14:49:14 -0700 Subject: [PATCH] include debug as env clean code. no null guard needed clean configfilehelper and settings.gradle fix comment --- newrelic-agent/src/main/java/com/newrelic/agent/Agent.java | 7 ++++++- .../java/com/newrelic/agent/config/AgentConfigImpl.java | 2 +- .../java/com/newrelic/agent/config/AgentJarHelper.java | 4 ++-- .../java/com/newrelic/agent/config/ConfigFileHelper.java | 4 +++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/Agent.java b/newrelic-agent/src/main/java/com/newrelic/agent/Agent.java index 2fdb444c08..53cd224caa 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/Agent.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/Agent.java @@ -51,7 +51,7 @@ public final class Agent { private static final String NEWRELIC_BOOTSTRAP = "newrelic-bootstrap"; private static final String AGENT_ENABLED_PROPERTY = "newrelic.config.agent_enabled"; - private static final boolean DEBUG = Boolean.getBoolean("newrelic.debug"); + private static final boolean DEBUG = Agent.setDebug(); private static final String VERSION = Agent.initVersion(); private static long agentPremainTime; @@ -76,6 +76,11 @@ public static boolean isDebugEnabled() { return DEBUG; } + private static boolean setDebug(){ + return Boolean.getBoolean("newrelic.debug") || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG")); + } + + private static volatile boolean canFastPath = true; /** diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentConfigImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentConfigImpl.java index 7c36b2341a..37e351fabe 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentConfigImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentConfigImpl.java @@ -293,7 +293,7 @@ private AgentConfigImpl(Map props) { putForDataSend = getProperty(PUT_FOR_DATA_SEND_PROPERTY, DEFAULT_PUT_FOR_DATA_SEND_ENABLED); isApdexTSet = getProperty(APDEX_T) != null; apdexTInMillis = (long) (getDoubleProperty(APDEX_T, DEFAULT_APDEX_T) * 1000L); - debug = Boolean.getBoolean(DEBUG); + debug = Boolean.getBoolean(DEBUG) || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG")); metricDebug = initMetricDebugConfig(); enabled = getProperty(ENABLED, DEFAULT_ENABLED) && getProperty(AGENT_ENABLED, DEFAULT_ENABLED); experimentalRuntime = allowExperimentalRuntimeVersions(); diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentJarHelper.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentJarHelper.java index d9072e3f74..2dd480d374 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentJarHelper.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/AgentJarHelper.java @@ -223,12 +223,12 @@ public static String getAgentJarAttribute(String name) { } } - // The "newrelic.debug" flag redirects all Agent logging to the standard output. Unfortunately, + // The "newrelic.debug" flag redirects all Agent logging (prior to log init) to the standard output -after log init, log as usual. Unfortunately, // we haven't initialized the Agent yet, so we cannot check it in the usual low-cost way by // calling Agent.isDebugEnabled(). So we duplicate the functionality here for use in a few cases. private static final boolean isNewRelicDebug() { final String newrelicDebug = "newrelic.debug"; - return System.getProperty(newrelicDebug) != null && Boolean.getBoolean(newrelicDebug); + return Boolean.getBoolean(newrelicDebug) || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG")); } // Use of this method should be limited to serious error cases that would cause the Agent to diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/ConfigFileHelper.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/ConfigFileHelper.java index 4dd27e3fde..30e638c0a4 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/ConfigFileHelper.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/ConfigFileHelper.java @@ -21,6 +21,8 @@ public class ConfigFileHelper { private static final String NEW_RELIC_HOME_DIRECTORY_PROPERTY = "newrelic.home"; private static final String NEW_RELIC_HOME_DIRECTORY_ENVIRONMENT_VARIABLE = "NEWRELIC_HOME"; private static final String NEW_RELIC_DEBUG_PROPERTY = "newrelic.debug"; + + private static final String NEW_RELIC_DEBUG_ENV = "NEWRELIC_DEBUG"; private static final String[] SEARCH_DIRECTORIES = { ".", "conf", "config", "etc" }; /** @@ -36,7 +38,7 @@ public static File findConfigFile() { File parentDir = getNewRelicDirectory(); if (parentDir != null) { - if (Boolean.getBoolean(NEW_RELIC_DEBUG_PROPERTY)) { + if (Boolean.getBoolean(NEW_RELIC_DEBUG_PROPERTY) || Boolean.parseBoolean(System.getenv(NEW_RELIC_DEBUG_ENV)) ) { System.err.println(MessageFormat.format("New Relic home directory: {0}", parentDir)); } }