Skip to content

Commit

Permalink
JS-357 Remove HttpClient logs from DEBUG level (#4876)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilia Kebets <[email protected]>
  • Loading branch information
saberduck and kebetsi authored Oct 18, 2024
1 parent d0227c4 commit af69740
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ public void testProject(File projectDir, String projectKey) {
.setProjectKey(projectKey)
.setSourceEncoding("UTF-8")
.setSourceDirs(".")
.setDebugLogs(true)
.setProjectDir(projectDir);

OrchestratorStarter.setProfile(projectKey, jsProfile, "js");
BuildResult buildResult = orchestrator.executeBuild(build);
assertThat(buildResult.getLogsLines(l -> l.startsWith("ERROR"))).isEmpty();
// assert that there are no logs from Apache HttpClient
assertThat(buildResult.getLogsLines(l -> l.contains("preparing request execution"))).isEmpty();

List<Issue> issuesList = getIssueList(projectKey, "javascript:S3923");
assertThat(issuesList).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.gson.JsonSyntaxException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -136,8 +138,32 @@ public BridgeServerImpl(
this.temporaryDeployLocation = tempFolder.newDir(BRIDGE_DEPLOY_LOCATION).toPath();
this.heartbeatService = Executors.newSingleThreadScheduledExecutor();
this.embeddedNode = embeddedNode;
silenceHttpClientLogs();
}

private static void silenceHttpClientLogs() {
setLoggerLevelToInfo("org.apache.hc");
}

/**
* This method sets the log level of the logger with the given name to INFO.
* It assumes that SLF4J is used as the logging facade and Logback as the logging implementation.
* Since we don't want to directly depend on logback, we use reflection to set the log level.
* @param loggerName
*/
private static void setLoggerLevelToInfo(String loggerName) {
try {
ClassLoader cl = BridgeServerImpl.class.getClassLoader();
Class<?> level = cl.loadClass("ch.qos.logback.classic.Level");
Logger logger = LoggerFactory.getLogger(loggerName);
Method setLevel = logger.getClass().getMethod("setLevel", level);
setLevel.invoke(logger, level.getField("INFO").get(null));
} catch (NoSuchFieldException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
LOG.info("Failed to set logger level to INFO for " + loggerName, e);
}
}


void heartbeat() {
LOG.trace("Pinging the bridge server");
isAlive();
Expand Down

0 comments on commit af69740

Please sign in to comment.