Skip to content

Commit

Permalink
allow to override fqcn in Log4jEventBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
oshai committed Jul 3, 2023
1 parent 83bba1b commit d5fb79a
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -43,6 +44,7 @@ public class Log4jEventBuilder implements LoggingEventBuilder {
private Throwable throwable = null;
private Map<String, String> keyValuePairs = null;
private final Level level;
private String fqcnOverride;

public Log4jEventBuilder(final Log4jMarkerFactory markerFactory, final Logger logger, final Level level) {
this.markerFactory = markerFactory;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -157,4 +160,8 @@ public void log(final Supplier<String> messageSupplier) {
log();
}

@Override
public void setCallerBoundary(String fqcn) {
fqcnOverride = fqcn;
}
}

0 comments on commit d5fb79a

Please sign in to comment.