Skip to content

Commit

Permalink
add support to log elapsedTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Forster committed Sep 13, 2013
1 parent dcfb0a0 commit 149d20f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
Expand Up @@ -18,6 +18,7 @@

import ch.qos.logback.access.pattern.ContentLengthConverter;
import ch.qos.logback.access.pattern.DateConverter;
import ch.qos.logback.access.pattern.ElapsedTimeConverter;
import ch.qos.logback.access.pattern.EnsureLineSeparation;
import ch.qos.logback.access.pattern.FullRequestConverter;
import ch.qos.logback.access.pattern.FullResponseConverter;
Expand Down Expand Up @@ -150,7 +151,8 @@ public class PatternLayout extends PatternLayoutBase<IAccessEvent> {
defaultConverterMap.put("fullRequest", FullRequestConverter.class.getName());
defaultConverterMap.put("fullResponse", FullResponseConverter.class.getName());


defaultConverterMap.put("elapsedTime", ElapsedTimeConverter.class.getName());

defaultConverterMap.put("n", LineSeparatorConverter.class.getName());

defaultConverterMap.put("black", BlackCompositeConverter.class.getName());
Expand Down
Expand Up @@ -47,6 +47,10 @@ public int getStatusCode() {
return response.getStatus();
}

public long getRequestTimestamp() {
return request.getTimeStamp();
}

public Map<String, String> buildResponseHeaderMap() {
Map<String, String> responseHeaderMap = new HashMap<String, String>();
HttpFields httpFields = response.getHttpFields();
Expand Down
@@ -0,0 +1,24 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2013, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.access.pattern;

import ch.qos.logback.access.spi.IAccessEvent;

public class ElapsedTimeConverter extends AccessConverter {

public String convert(IAccessEvent accessEvent) {
return Long.toString(accessEvent.getElapsedTime());
}

}
Expand Up @@ -358,6 +358,13 @@ public int getStatusCode() {
return statusCode;
}

public long getElapsedTime() {
if (serverAdapter.getRequestTimestamp() < 0) {
return -1;
}
return timeStamp - serverAdapter.getRequestTimestamp();
}

public String getRequestContent() {
if (requestContent != null) {
return requestContent;
Expand Down Expand Up @@ -482,6 +489,7 @@ public void prepareForDeferredProcessing() {
getRequestURL();
getServerName();
getTimeStamp();
getElapsedTime();

getStatusCode();
getContentLength();
Expand Down
Expand Up @@ -60,6 +60,11 @@ public interface IAccessEvent extends DeferredProcessingAware {
*/
long getTimeStamp();

/**
* The time elapsed between receiving the request and logging it.
*/
long getElapsedTime();

String getRequestURI();

/**
Expand Down
Expand Up @@ -24,6 +24,7 @@
*/
public interface ServerAdapter {

long getRequestTimestamp();
long getContentLength();
int getStatusCode();
Map<String, String> buildResponseHeaderMap();
Expand Down
Expand Up @@ -44,7 +44,10 @@ public int getStatusCode() {
return response.getStatus();
}


public long getRequestTimestamp() {
return -1;
}

public Map<String, String> buildResponseHeaderMap() {
Map<String, String> responseHeaderMap = new HashMap<String, String>();
for (String key : response.getHeaderNames()) {
Expand Down
Expand Up @@ -34,6 +34,10 @@ public long getContentLength() {
public int getStatusCode() {
return response.getStatus();
}

public long getRequestTimestamp() {
return -1;
}

public Map<String, String> buildResponseHeaderMap() {
return response.headerMap;
Expand Down

0 comments on commit 149d20f

Please sign in to comment.