From a9a623d1dc91f0a228b0410f4a381c56ae325c2c Mon Sep 17 00:00:00 2001 From: Nikolay Martynov Date: Mon, 17 Jun 2019 12:56:19 -0400 Subject: [PATCH] Configure system logger to log timestamp Also add an 'identifying marker' to tracing log lines so we could potentially automatically parse them. --- .../datadog/trace/agent/TracingAgent.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java b/dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java index 2e402de6f5..db01e09f98 100644 --- a/dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java +++ b/dd-java-agent/src/main/java/datadog/trace/agent/TracingAgent.java @@ -15,6 +15,16 @@ import java.util.jar.JarFile; /** Entry point for initializing the agent. */ public class TracingAgent { + + private static final String SIMPLE_LOGGER_SHOW_DATE_TIME_PROPERTY = + "datadog.slf4j.simpleLogger.showDateTime"; + private static final String SIMPLE_LOGGER_DATE_TIME_FORMAT_PROPERTY = + "datadog.slf4j.simpleLogger.dateTimeFormat"; + private static final String SIMPLE_LOGGER_DATE_TIME_FORMAT_DEFAULT = + "'[dd.tracing.agent - 'yyyy-MM-dd HH:mm:ss:SSS Z']'"; + private static final String SIMPLE_LOGGER_DEFAULT_LOG_LEVEL_PROPERTY = + "datadog.slf4j.simpleLogger.defaultLogLevel"; + // fields must be managed under class lock private static ClassLoader AGENT_CLASSLOADER = null; private static ClassLoader JMXFETCH_CLASSLOADER = null; @@ -28,6 +38,7 @@ public class TracingAgent { public static void agentmain(final String agentArgs, final Instrumentation inst) throws Exception { + configureLogger(); startDatadogAgent(agentArgs, inst); if (isAppUsingCustomLogManager()) { System.out.println("Custom logger detected. Delaying JMXFetch initialization."); @@ -113,6 +124,18 @@ public class TracingAgent { } } + private static void configureLogger() { + setSystemPropertyDefault(SIMPLE_LOGGER_SHOW_DATE_TIME_PROPERTY, "true"); + setSystemPropertyDefault( + SIMPLE_LOGGER_DATE_TIME_FORMAT_PROPERTY, SIMPLE_LOGGER_DATE_TIME_FORMAT_DEFAULT); + } + + private static void setSystemPropertyDefault(final String property, final String value) { + if (System.getProperty(property) == null) { + System.setProperty(property, value); + } + } + /** * Extract embeded jars out of the dd-java-agent to a temporary location. * @@ -228,7 +251,7 @@ public class TracingAgent { */ private static boolean isAppUsingCustomLogManager() { final boolean debugEnabled = - "debug".equalsIgnoreCase(System.getProperty("datadog.slf4j.simpleLogger.defaultLogLevel")); + "debug".equalsIgnoreCase(System.getProperty(SIMPLE_LOGGER_DEFAULT_LOG_LEVEL_PROPERTY)); final String tracerCustomLogManSysprop = "dd.app.customlogmanager"; final String customLogManagerProp = System.getProperty(tracerCustomLogManSysprop);