diff --git a/log4j-slf4j2-impl/src/main/java/org/apache/logging/slf4j/Log4jEventBuilder.java b/log4j-slf4j2-impl/src/main/java/org/apache/logging/slf4j/Log4jEventBuilder.java index bce6ffdd1504..a9c16f620462 100644 --- a/log4j-slf4j2-impl/src/main/java/org/apache/logging/slf4j/Log4jEventBuilder.java +++ b/log4j-slf4j2-impl/src/main/java/org/apache/logging/slf4j/Log4jEventBuilder.java @@ -29,9 +29,10 @@ import org.apache.logging.log4j.LogBuilder; import org.apache.logging.log4j.Logger; import org.slf4j.Marker; +import org.slf4j.spi.CallerBoundaryAware; import org.slf4j.spi.LoggingEventBuilder; -public class Log4jEventBuilder implements LoggingEventBuilder { +public class Log4jEventBuilder implements LoggingEventBuilder, CallerBoundaryAware { private static final String FQCN = Log4jEventBuilder.class.getName(); @@ -43,6 +44,7 @@ public class Log4jEventBuilder implements LoggingEventBuilder { private Throwable throwable = null; private Map keyValuePairs = null; private final Level level; + private String fqcnOverride; public Log4jEventBuilder(final Log4jMarkerFactory markerFactory, final Logger logger, final Level level) { this.markerFactory = markerFactory; @@ -110,7 +112,8 @@ public void log() { .withMarker(marker) .withThrowable(throwable); if (logBuilder instanceof BridgeAware) { - ((BridgeAware) logBuilder).setEntryPoint(FQCN); + String fcqn = fqcnOverride != null ? fqcnOverride : FQCN; + ((BridgeAware) logBuilder).setEntryPoint(fcqn); } if (keyValuePairs == null || keyValuePairs.isEmpty()) { logBuilder.log(message, arguments.toArray()); @@ -157,4 +160,8 @@ public void log(final Supplier messageSupplier) { log(); } + @Override + public void setCallerBoundary(String fqcn) { + fqcnOverride = fqcn; + } }