Skip to content

Commit

Permalink
Remove catch Throwable, reduce @NoMuzzle annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Nov 16, 2024
1 parent eb7bf1f commit 90b759d
Showing 1 changed file with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,10 @@ private static boolean supportsMultipleMarkers() {

private static void captureLogstashAttributes(
AttributesBuilder attributes, ILoggingEvent loggingEvent) {
try {
if (supportsMultipleMarkers && hasMultipleMarkers(loggingEvent)) {
captureMultipleLogstashAttributes(attributes, loggingEvent);
} else {
captureSingleLogstashAttribute(attributes, loggingEvent);
}
} catch (Throwable e) {
// ignore
if (supportsMultipleMarkers && hasMultipleMarkers(loggingEvent)) {
captureMultipleLogstashAttributes(attributes, loggingEvent);
} else {
captureSingleLogstashAttribute(attributes, loggingEvent);
}
}

Expand All @@ -465,13 +461,11 @@ private static boolean isLogstashMarker(Marker marker) {
}

@SuppressWarnings("deprecation") // getMarker is deprecate since 1.3.0
@NoMuzzle
private static void captureSingleLogstashAttribute(
AttributesBuilder attributes, ILoggingEvent loggingEvent) {
Marker marker = loggingEvent.getMarker();
if (isLogstashMarker(marker)) {
LogstashMarker logstashMarker = (LogstashMarker) marker;
captureLogstashMarker(attributes, logstashMarker);
captureLogstashMarker(attributes, marker);
}
}

Expand All @@ -480,31 +474,28 @@ private static void captureMultipleLogstashAttributes(
AttributesBuilder attributes, ILoggingEvent loggingEvent) {
for (Marker marker : loggingEvent.getMarkerList()) {
if (isLogstashMarker(marker)) {
LogstashMarker logstashMarker = (LogstashMarker) marker;
captureLogstashMarker(attributes, logstashMarker);
captureLogstashMarker(attributes, marker);
}
}
}

@NoMuzzle
private static void captureLogstashMarker(
AttributesBuilder attributes, LogstashMarker logstashMarker) {
private static void captureLogstashMarker(AttributesBuilder attributes, Marker marker) {
LogstashMarker logstashMarker = (LogstashMarker) marker;
captureLogstashMarkerAttributes(attributes, logstashMarker);

if (logstashMarker.hasReferences()) {
for (Iterator<Marker> it = logstashMarker.iterator(); it.hasNext(); ) {
Marker referenceMarker = it.next();
if (isLogstashMarker(referenceMarker)) {
LogstashMarker referenceLogstashMarker = (LogstashMarker) referenceMarker;
captureLogstashMarker(attributes, referenceLogstashMarker);
captureLogstashMarker(attributes, referenceMarker);
}
}
}
}

@NoMuzzle
private static void captureLogstashMarkerAttributes(
AttributesBuilder attributes, LogstashMarker logstashMarker) {
AttributesBuilder attributes, Object logstashMarker) {
FieldReader fieldReader = valueField.get(logstashMarker.getClass());
if (fieldReader != null) {
fieldReader.read(attributes, logstashMarker);
Expand Down Expand Up @@ -608,7 +599,7 @@ private static boolean supportsLogstashMarkers() {
}

private interface FieldReader {
void read(AttributesBuilder attributes, LogstashMarker logstashMarker);
void read(AttributesBuilder attributes, Object logstashMarker);
}

/**
Expand Down

0 comments on commit 90b759d

Please sign in to comment.