@Test public void testCommonLogFormat() throws Exception { final long time = SystemTime.asMillis(); SystemTime.setTimeSource(new TimeSource() { public long millis() { return time; } }); DateFormat dateFormat = HttpRequestLogFormatter.dateFormat; String timestamp = dateFormat.format(SystemTime.asDate()); String expected = "1.2.3.4 - bob [" + timestamp + "] \"GET /ctx/path/resource HTTP/1.1\" 200 2326"; HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getRemoteAddr()).andReturn("1.2.3.4"); expect(request.getRemoteUser()).andReturn("bob"); expect(request.getMethod()).andReturn("GET"); expect(request.getRequestURI()).andReturn( "/ctx/path/resource"); expect(request.getProtocol()).andReturn("HTTP/1.1"); replay(request); HttpRequestLogFormatter formatter = new HttpRequestLogFormatter(); assertEquals(expected, formatter.format(request, 200, 2326)); }
public String format(HttpServletRequest request, int httpStatus, int contentLength) { StringBuffer line = new StringBuffer(); line.append(request.getRemoteAddr()); line.append(" - "); line.append(request.getRemoteUser()); line.append(" ["); line.append(dateFormat.format(SystemTime.asDate())); line.append("] \"").append(request.getMethod()); line.append(" ").append(request.getRequestURI()); line.append(" ").append(request.getProtocol()); line.append("\" ").append(httpStatus); line.append(" ").append(contentLength); return line.toString(); }
HttpRequestLogFormatter { public String format(HttpServletRequest request, int httpStatus, int contentLength) { StringBuffer line = new StringBuffer(); line.append(request.getRemoteAddr()); line.append(" - "); line.append(request.getRemoteUser()); line.append(" ["); line.append(dateFormat.format(SystemTime.asDate())); line.append("] \"").append(request.getMethod()); line.append(" ").append(request.getRequestURI()); line.append(" ").append(request.getProtocol()); line.append("\" ").append(httpStatus); line.append(" ").append(contentLength); return line.toString(); } }
HttpRequestLogFormatter { public String format(HttpServletRequest request, int httpStatus, int contentLength) { StringBuffer line = new StringBuffer(); line.append(request.getRemoteAddr()); line.append(" - "); line.append(request.getRemoteUser()); line.append(" ["); line.append(dateFormat.format(SystemTime.asDate())); line.append("] \"").append(request.getMethod()); line.append(" ").append(request.getRequestURI()); line.append(" ").append(request.getProtocol()); line.append("\" ").append(httpStatus); line.append(" ").append(contentLength); return line.toString(); }  }
HttpRequestLogFormatter { public String format(HttpServletRequest request, int httpStatus, int contentLength) { StringBuffer line = new StringBuffer(); line.append(request.getRemoteAddr()); line.append(" - "); line.append(request.getRemoteUser()); line.append(" ["); line.append(dateFormat.format(SystemTime.asDate())); line.append("] \"").append(request.getMethod()); line.append(" ").append(request.getRequestURI()); line.append(" ").append(request.getProtocol()); line.append("\" ").append(httpStatus); line.append(" ").append(contentLength); return line.toString(); }  String format(HttpServletRequest request, int httpStatus,
			int contentLength); }
HttpRequestLogFormatter { public String format(HttpServletRequest request, int httpStatus, int contentLength) { StringBuffer line = new StringBuffer(); line.append(request.getRemoteAddr()); line.append(" - "); line.append(request.getRemoteUser()); line.append(" ["); line.append(dateFormat.format(SystemTime.asDate())); line.append("] \"").append(request.getMethod()); line.append(" ").append(request.getRequestURI()); line.append(" ").append(request.getProtocol()); line.append("\" ").append(httpStatus); line.append(" ").append(contentLength); return line.toString(); }  String format(HttpServletRequest request, int httpStatus,
			int contentLength); static DateFormat dateFormat; }