Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reduce apache http logging #6280

Merged
merged 1 commit into from Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions ant/src/main/java/org/owasp/dependencycheck/taskdefs/Purge.java
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
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
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