Structure send method of Slf4jEventSender
By extracting code into subroutines it is easier to override parts e.g. to make used Logger dependent of called method
@@ -38,10 +38,26 @@ public class Slf4jEventSender implements LogEventSender {
@Override
public void send(LogEvent event) {
- String cat = "org.apache.cxf.services." + event.getPortTypeName().getLocalPart() + "." + event.getType();
- Logger log = LoggerFactory.getLogger(cat);
+ Logger log = getLogger(event);
Set<String> keys = new HashSet<>();
try {
+ fillMDC(event, keys);
+ performLogging(log, MarkerFactory.getMarker(event.getServiceName() != null ? "SOAP" : "REST"),
+ getLogMessage(event));
+ } finally {
+ for (String key : keys) {
+ MDC.remove(key);
+ }
+ }
+
+ }
+
+ protected Logger getLogger(final LogEvent event) {
+ final String cat = "org.apache.cxf.services." + event.getPortTypeName().getLocalPart() + "." + event.getType();
+ return LoggerFactory.getLogger(cat);
+ }
+
+ protected void fillMDC(final LogEvent event, final Set<String> keys) {
put(keys, "Type", event.getType().toString());
put(keys, "Address", event.getAddress());
put(keys, "HttpMethod", event.getHttpMethod());
@@ -58,14 +74,6 @@ public class Slf4jEventSender implements LogEventSender {
put(keys, "FullContentFile", event.getFullContentFile().getAbsolutePath());
}
put(keys, "Headers", event.getHeaders().toString());
- performLogging(log, MarkerFactory.getMarker(event.getServiceName() != null ? "SOAP" : "REST"),
- getLogMessage(event));
- } finally {
- for (String key : keys) {
- MDC.remove(key);
- }
- }
-
}
/**
