diff --git a/.travis.yml b/.travis.yml index 0fb948de8..fe51ee58c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,17 +18,17 @@ matrix: - jdk: oraclejdk8 env: - DESC="Oracle JDK8 testing" - - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties" + - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties -Dtests.log_level=info" - jdk: oraclejdk7 env: - DESC="Oracle JDK7 testing" - - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties" + - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties -Dtests.log_level=info" - jdk: openjdk7 env: - DESC="OpenJDK7 testing" - - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties" + - CMD="mvn test -B -Dhttps.protocols=TLSv1.2 -Dcheckstyle.skip=true -Dlog4j.configurationFile=log4j2.travis.properties -Dtests.log_level=info" script: echo "Running $DESC..." && (eval $CMD) diff --git a/log4j2.travis.properties b/log4j2.travis.properties index 3c926875d..f81b23307 100644 --- a/log4j2.travis.properties +++ b/log4j2.travis.properties @@ -6,4 +6,5 @@ appender.console.name = CONSOLE appender.console.layout.type = PatternLayout appender.console.layout.pattern = %p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n appender.console.filter.threshold.type = ThresholdFilter -appender.console.filter.threshold.level = info +appender.console.filter.threshold.level = all +# appender.console.filter.threshold.level = info diff --git a/src/main/java/org/datadog/jmxfetch/util/CustomLogger.java b/src/main/java/org/datadog/jmxfetch/util/CustomLogger.java index 5902e3fc3..0d2cd73a0 100644 --- a/src/main/java/org/datadog/jmxfetch/util/CustomLogger.java +++ b/src/main/java/org/datadog/jmxfetch/util/CustomLogger.java @@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.core.Filter.Result; +import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.appender.ConsoleAppender; import org.apache.logging.log4j.core.appender.RollingFileAppender; @@ -15,9 +15,10 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.LoggerConfig; -import org.apache.logging.log4j.core.filter.ThresholdFilter; import org.apache.logging.log4j.core.layout.PatternLayout; + + @Slf4j public class CustomLogger { private static final Multiset messageCount = HashMultiset.create(); @@ -38,6 +39,11 @@ public static void setup(Level level, String logLocation, boolean logFormatRfc33 String logPattern = logFormatRfc3339 ? LAYOUT_RFC3339 : LAYOUT; + PatternLayout layout = PatternLayout.newBuilder() + .withConfiguration(config) + .withPattern(logPattern) + .build(); + if (logLocation != null && !ConsoleAppender.Target.SYSTEM_ERR.toString().equals(logLocation) && !SYSTEM_ERR_ALT.equals(logLocation) @@ -46,11 +52,6 @@ public static void setup(Level level, String logLocation, boolean logFormatRfc33 target = "FileLogger"; - PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(config) - .withPattern(logPattern) - .build(); - RollingFileAppender fa = RollingFileAppender.newBuilder() .setConfiguration(config) .withName(target) @@ -77,11 +78,6 @@ public static void setup(Level level, String logLocation, boolean logFormatRfc33 config.getRootLogger().removeAppender("CONSOLE"); ctx.updateLoggers(); - PatternLayout layout = PatternLayout.newBuilder() - .withConfiguration(config) - .withPattern(logPattern) - .build(); - ConsoleAppender ca = ConsoleAppender.newBuilder() .setConfiguration(config) .withName(logLocation) @@ -95,8 +91,20 @@ public static void setup(Level level, String logLocation, boolean logFormatRfc33 } } + // replace default appender with the correct layout LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); + loggerConfig.removeAppender(target); + + Appender appender = ConsoleAppender.newBuilder() + .setConfiguration(config) + .withName(target) + .withLayout(layout) + .build(); + appender.start(); + + loggerConfig.addAppender(appender, null, null); loggerConfig.setLevel(level); + ctx.updateLoggers(); } diff --git a/src/test/java/org/datadog/jmxfetch/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java index ca48eef3c..fac6340bb 100644 --- a/src/test/java/org/datadog/jmxfetch/TestCommon.java +++ b/src/test/java/org/datadog/jmxfetch/TestCommon.java @@ -42,7 +42,11 @@ public class TestCommon { /** Setup logger. */ @BeforeClass public static void init() throws Exception { - CustomLogger.setup(Level.toLevel("ALL"), "/tmp/jmxfetch_test.log", false); + String level = System.getProperty("tests.log_level"); + if (level == null) { + level = "ALL"; + } + CustomLogger.setup(Level.toLevel(level), "/tmp/jmxfetch_test.log", false); } /**