fix(): also check exceptions/stack trace when filtering log messages (#10391)

Co-authored-by: John Joyce <john@acryl.io>
This commit is contained in:
Felix Lüdin 2024-07-04 01:28:58 +02:00 committed by GitHub
parent 581dc7ffe2
commit 87ff19ed48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,8 @@
package com.linkedin.metadata.utils.log; package com.linkedin.metadata.utils.log;
import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.ThrowableProxyUtil;
import ch.qos.logback.core.filter.AbstractMatcherFilter; import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply; import ch.qos.logback.core.spi.FilterReply;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,7 +23,21 @@ public class LogMessageFilter extends AbstractMatcherFilter<ILoggingEvent> {
return FilterReply.NEUTRAL; return FilterReply.NEUTRAL;
} }
if (this.excluded.stream().anyMatch(message -> event.getFormattedMessage().contains(message))) { final String formattedMessage = event.getFormattedMessage();
final IThrowableProxy throwableProxy = event.getThrowableProxy();
String throwableString;
if (throwableProxy != null) {
throwableString = ThrowableProxyUtil.asString(throwableProxy);
} else {
throwableString = null;
}
if (this.excluded.stream()
.anyMatch(
message ->
formattedMessage.contains(message)
|| (throwableString != null && throwableString.contains(message)))) {
return FilterReply.DENY; return FilterReply.DENY;
} }
return FilterReply.ACCEPT; return FilterReply.ACCEPT;