Add filters/tasks to enable/disable request logging.

This commit is contained in:
Jon Chambers
2020-10-20 15:27:36 -04:00
committed by Jon Chambers
parent ab62c19de9
commit 1732cf9243
9 changed files with 110 additions and 12 deletions

View File

@@ -0,0 +1,18 @@
package org.whispersystems.textsecuregcm.util.logging;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;
class RequestLogEnabledFilter<E> extends Filter<E> {
private volatile boolean requestLoggingEnabled = false;
@Override
public FilterReply decide(final E event) {
return requestLoggingEnabled ? FilterReply.NEUTRAL : FilterReply.DENY;
}
public void setRequestLoggingEnabled(final boolean requestLoggingEnabled) {
this.requestLoggingEnabled = requestLoggingEnabled;
}
}

View File

@@ -0,0 +1,15 @@
package org.whispersystems.textsecuregcm.util.logging;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.filter.Filter;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.logging.filter.FilterFactory;
@JsonTypeName("requestLogEnabled")
class RequestLogEnabledFilterFactory implements FilterFactory<IAccessEvent> {
@Override
public Filter<IAccessEvent> build() {
return RequestLogManager.getHttpRequestLogFilter();
}
}

View File

@@ -0,0 +1,17 @@
package org.whispersystems.textsecuregcm.util.logging;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.filter.Filter;
import org.whispersystems.websocket.logging.WebsocketEvent;
public class RequestLogManager {
private static final RequestLogEnabledFilter<IAccessEvent> HTTP_REQUEST_LOG_FILTER = new RequestLogEnabledFilter<>();
static Filter<IAccessEvent> getHttpRequestLogFilter() {
return HTTP_REQUEST_LOG_FILTER;
}
public static void setRequestLoggingEnabled(final boolean enabled) {
HTTP_REQUEST_LOG_FILTER.setRequestLoggingEnabled(enabled);
}
}