Skip to content

Commit

Permalink
SONAR-9069 silence MsSQL driver logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb authored and ehartmann committed May 29, 2017
1 parent e7f0cea commit 608bd9c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.ce.log;

import ch.qos.logback.classic.Level;
import org.sonar.process.ProcessId;
import org.sonar.process.logging.LogDomain;
import org.sonar.process.logging.LogLevelConfig;
Expand All @@ -40,6 +41,7 @@ protected void extendLogLevelConfiguration(LogLevelConfig.Builder logLevelConfig
logLevelConfigBuilder.levelByDomain("sql", ProcessId.COMPUTE_ENGINE, LogDomain.SQL);
logLevelConfigBuilder.levelByDomain("es", ProcessId.COMPUTE_ENGINE, LogDomain.ES);
JMX_RMI_LOGGER_NAMES.forEach(loggerName -> logLevelConfigBuilder.levelByDomain(loggerName, ProcessId.COMPUTE_ENGINE, LogDomain.JMX));
MSQDRIVER_LOGGER_NAMES_TO_TURN_OFF.forEach(loggerName -> logLevelConfigBuilder.immutableLevel(loggerName, Level.OFF));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public abstract class ServerProcessLogging {
"sun.rmi.transport.misc",
"sun.rmi.server.call",
"sun.rmi.dgc");
protected static final Set<String> MSQDRIVER_LOGGER_NAMES_TO_TURN_OFF = ImmutableSet.of(
"com.microsoft.sqlserver.jdbc.internals",
"com.microsoft.sqlserver.jdbc.ResultSet",
"com.microsoft.sqlserver.jdbc.Statement",
"com.microsoft.sqlserver.jdbc.Connection");
private final ProcessId processId;
private final String threadIdFieldPattern;
private final LogbackHelper helper = new LogbackHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.server.app;

import ch.qos.logback.classic.Level;
import java.util.logging.LogManager;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.sonar.process.ProcessId;
Expand Down Expand Up @@ -46,6 +47,8 @@ protected void extendLogLevelConfiguration(LogLevelConfig.Builder logLevelConfig
logLevelConfigBuilder.offUnlessTrace("org.apache.catalina.core.ContainerBase");
logLevelConfigBuilder.offUnlessTrace("org.apache.catalina.core.StandardContext");
logLevelConfigBuilder.offUnlessTrace("org.apache.catalina.core.StandardService");

MSQDRIVER_LOGGER_NAMES_TO_TURN_OFF.forEach(loggerName -> logLevelConfigBuilder.immutableLevel(loggerName, Level.OFF));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.stream.Stream;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -426,6 +427,17 @@ public void configure_defines_hardcoded_levels_unchanged_by_ce_property() {
verifyImmutableLogLevels(context);
}

@Test
public void configure_turns_off_some_MsSQL_driver_logger() {
LoggerContext context = underTest.configure(props);

Stream.of("com.microsoft.sqlserver.jdbc.internals",
"com.microsoft.sqlserver.jdbc.ResultSet",
"com.microsoft.sqlserver.jdbc.Statement",
"com.microsoft.sqlserver.jdbc.Connection")
.forEach(loggerName -> assertThat(context.getLogger(loggerName).getLevel()).isEqualTo(Level.OFF));
}

private void verifyRootLogLevel(LoggerContext ctx, Level expected) {
assertThat(ctx.getLogger(ROOT_LOGGER_NAME).getLevel()).isEqualTo(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.stream.Stream;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -462,6 +463,17 @@ public void configure_turns_off_some_Tomcat_loggers_if_global_log_level_is_TRACE
assertThat(context.getLogger("org.apache.catalina.core.StandardService").getLevel()).isNull();
}

@Test
public void configure_turns_off_some_MsSQL_driver_logger() {
LoggerContext context = underTest.configure(props);

Stream.of("com.microsoft.sqlserver.jdbc.internals",
"com.microsoft.sqlserver.jdbc.ResultSet",
"com.microsoft.sqlserver.jdbc.Statement",
"com.microsoft.sqlserver.jdbc.Connection")
.forEach(loggerName -> assertThat(context.getLogger(loggerName).getLevel()).isEqualTo(Level.OFF));
}

private void verifyRootLogLevel(LoggerContext ctx, Level expected) {
Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
assertThat(rootLogger.getLevel()).isEqualTo(expected);
Expand Down

0 comments on commit 608bd9c

Please sign in to comment.