Make this a bit easier to read
This commit is contained in:
parent
f5823a8e2f
commit
812870f5dc
|
@ -52,46 +52,47 @@ import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
|
|||
*/
|
||||
public class LoggingInterceptor extends InterceptorAdapter {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(LoggingInterceptor.class);
|
||||
private final class MyLookup extends StrLookup<String> {
|
||||
private final HttpServletRequest myRequest;
|
||||
private final RequestDetails myRequestDetails;
|
||||
|
||||
private Logger myLogger = ourLog;
|
||||
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
||||
private MyLookup(HttpServletRequest theRequest, RequestDetails theRequestDetails) {
|
||||
myRequest = theRequest;
|
||||
myRequestDetails = theRequestDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incomingRequest(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
||||
StrLookup<?> lookup = new StrLookup<String>() {
|
||||
@Override
|
||||
public String lookup(String theKey) {
|
||||
if ("operationType".equals(theKey)) {
|
||||
if (theRequestDetails.getResourceOperationType() != null) {
|
||||
return theRequestDetails.getResourceOperationType().getCode();
|
||||
if (myRequestDetails.getResourceOperationType() != null) {
|
||||
return myRequestDetails.getResourceOperationType().getCode();
|
||||
}
|
||||
if (theRequestDetails.getSystemOperationType() != null) {
|
||||
return theRequestDetails.getSystemOperationType().getCode();
|
||||
if (myRequestDetails.getSystemOperationType() != null) {
|
||||
return myRequestDetails.getSystemOperationType().getCode();
|
||||
}
|
||||
if (theRequestDetails.getOtherOperationType() != null) {
|
||||
return theRequestDetails.getOtherOperationType().getCode();
|
||||
if (myRequestDetails.getOtherOperationType() != null) {
|
||||
return myRequestDetails.getOtherOperationType().getCode();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ("id".equals(theKey)) {
|
||||
if (theRequestDetails.getId() != null) {
|
||||
return theRequestDetails.getId().getValue();
|
||||
if (myRequestDetails.getId() != null) {
|
||||
return myRequestDetails.getId().getValue();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ("idOrResourceName".equals(theKey)) {
|
||||
if (theRequestDetails.getId() != null) {
|
||||
return theRequestDetails.getId().getValue();
|
||||
if (myRequestDetails.getId() != null) {
|
||||
return myRequestDetails.getId().getValue();
|
||||
}
|
||||
if (theRequestDetails.getResourceName() != null) {
|
||||
return theRequestDetails.getResourceName();
|
||||
if (myRequestDetails.getResourceName() != null) {
|
||||
return myRequestDetails.getResourceName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (theKey.equals("requestParameters")) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (Entry<String, String[]> next : theRequestDetails.getParameters().entrySet()) {
|
||||
for (Entry<String, String[]> next : myRequestDetails.getParameters().entrySet()) {
|
||||
for (String nextValue : next.getValue()) {
|
||||
if (b.length() == 0) {
|
||||
b.append('?');
|
||||
|
@ -110,17 +111,29 @@ public class LoggingInterceptor extends InterceptorAdapter {
|
|||
return b.toString();
|
||||
}
|
||||
if (theKey.startsWith("requestHeader.")) {
|
||||
String val = theRequest.getHeader(theKey.substring("requestHeader.".length()));
|
||||
String val = myRequest.getHeader(theKey.substring("requestHeader.".length()));
|
||||
return StringUtils.defaultString(val);
|
||||
}
|
||||
if (theKey.startsWith("remoteAddr")) {
|
||||
return StringUtils.defaultString(theRequest.getRemoteAddr());
|
||||
return StringUtils.defaultString(myRequest.getRemoteAddr());
|
||||
}
|
||||
return "!VAL!";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(LoggingInterceptor.class);
|
||||
|
||||
private Logger myLogger = ourLog;
|
||||
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
||||
|
||||
@Override
|
||||
public boolean incomingRequest(final RequestDetails theRequestDetails, final HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
|
||||
|
||||
// Perform any string substitutions from the message format
|
||||
StrLookup<?> lookup = new MyLookup(theRequest, theRequestDetails);
|
||||
StrSubstitutor subs = new StrSubstitutor(lookup, "${", "}", '\\');
|
||||
|
||||
// Actuall log the line
|
||||
String line = subs.replace(myMessageFormat);
|
||||
myLogger.info(line);
|
||||
|
||||
|
|
Loading…
Reference in New Issue