}
@Override
public Object[] getFieldsToLog() {
GeoLocationDetails location = context != null ? context.getLocation() : null;
// This is a bit (deeply!) ugly, but it is necessary as it is not possible to know
// if a response is gzipped until after it is written. Therefore the only other solution
// would be to pollute the command object with a getCompression() method, which
// (a) seems overkill for a simple logger.
// (b) just moves the problem to the jetty transport.
String compression = "none";
try {
if (command.getResponse().getOutputStream().getClass().getSimpleName().contains("GzipStream")) {
compression = "gzip";
}
} catch (Exception e) {
// ho hum. Let's assume it's not compressed
}
// Check the extra loggable fields.
List<String> extraFields;
if (headersToLog.isEmpty()) {
extraFields = Collections.emptyList();
} else {
extraFields = new ArrayList<String>();
for (String headerName: headersToLog) {
String value = HeaderUtils.cleanHeaderValue(command.getRequest().getHeader(headerName));
if (value != null && value.length() > 0) {
extraFields.add(headerName+"="+value);
}
}
}
return new Object[] {
command.getTimer().getReceivedTime(),
context != null ? context.getRequestUUID() : "",
command.getFullPath(),
compression,
location != null ? location.getRemoteAddr() : "",
location != null ? format(location.getResolvedAddresses()) : "",
location != null ? location.getCountry() : "",
responseCode,
command.getTimer().getProcessTimeNanos(),
bytesRead,
bytesWritten,
requestMediaType != null ? requestMediaType.getSubtype() : "",