Skip to content

Commit

Permalink
Added responseTime to the LoggingFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
rvema committed Dec 4, 2018
1 parent 220e805 commit d0a720e
Showing 1 changed file with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.capitalone.dashboard.logging;


import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.capitalone.dashboard.model.RequestLog;
import com.capitalone.dashboard.repository.RequestLogRepository;
import com.capitalone.dashboard.settings.ApiSettings;
import com.mongodb.util.JSON;
import org.apache.commons.io.output.TeeOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;

import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
Expand All @@ -36,17 +27,24 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.io.output.TeeOutputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;

import com.capitalone.dashboard.settings.ApiSettings;
import com.capitalone.dashboard.model.RequestLog;
import com.capitalone.dashboard.repository.RequestLogRepository;
import com.mongodb.util.JSON;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

//import org.springframework.util.MimeType;

Expand Down Expand Up @@ -81,7 +79,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
BufferedRequestWrapper bufferedRequest = new BufferedRequestWrapper(httpServletRequest);
BufferedResponseWrapper bufferedResponse = new BufferedResponseWrapper(httpServletResponse);


long startTime = System.currentTimeMillis();
RequestLog requestLog = new RequestLog();
requestLog.setClient(httpServletRequest.getRemoteAddr());
requestLog.setEndpoint(httpServletRequest.getRequestURI());
Expand All @@ -105,7 +103,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
requestLog.setResponseSize(bufferedResponse.getContent().length());

requestLog.setResponseCode(bufferedResponse.getStatus());
requestLog.setTimestamp(System.currentTimeMillis());
long endTime = System.currentTimeMillis();
requestLog.setResponseTime(endTime - startTime);
requestLog.setTimestamp(endTime);
try {
requestLogRepository.save(requestLog);
} catch (RuntimeException re) {
Expand Down

0 comments on commit d0a720e

Please # to comment.