Skip to content

Commit

Permalink
fix: reduce apache http logging (#6280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong authored Dec 12, 2023
1 parent 2a388f1 commit 17186db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions ant/src/main/java/org/owasp/dependencycheck/taskdefs/Purge.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void setHostedSuppressionsUrl(final String hostedSuppressionsUrl) {
*/
@Override
public final void execute() throws BuildException {
muteJCS();
muteNoisyLoggers();
final ClassLoader current = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
Expand All @@ -161,9 +161,16 @@ public final void execute() throws BuildException {
/**
* Hacky method of muting the noisy logging from JCS.
*/
private void muteJCS() {
private void muteNoisyLoggers() {
System.setProperty("jcs.logSystem", "slf4j");
Slf4jAdapter.muteLogging(true);

final String[] noisyLoggers = {
"org.apache.hc"
};
for (String loggerName : noisyLoggers) {
System.setProperty("org.slf4j.simpleLogger.log." + loggerName, "error");
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</appender>

<logger name="org.apache.commons.jcs" level="ERROR" />
<logger name="org.apache.hc" level="ERROR" />

<root level="INFO">
<appender-ref ref="console"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import org.apache.maven.artifact.repository.ArtifactRepository;

import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
Expand Down Expand Up @@ -1929,7 +1930,7 @@ public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest(MavenProj
* fail the build
*/
protected void runCheck() throws MojoExecutionException, MojoFailureException {
muteJCS();
muteNoisyLoggers();
try (Engine engine = initializeEngine()) {
ExceptionCollection exCol = null;
if (scanDependencies) {
Expand Down Expand Up @@ -2498,11 +2499,18 @@ private String[] determineSuppressions() {
/**
* Hacky method of muting the noisy logging from JCS
*/
private void muteJCS() {
private void muteNoisyLoggers() {
System.setProperty("jcs.logSystem", "slf4j");
if (!getLog().isDebugEnabled()) {
Slf4jAdapter.muteLogging(true);
}

final String[] noisyLoggers = {
"org.apache.hc"
};
for (String loggerName : noisyLoggers) {
System.setProperty("org.slf4j.simpleLogger.log." + loggerName, "error");
}
}

/**
Expand Down

0 comments on commit 17186db

Please sign in to comment.