JsonLayout extends JsonLayoutBase<IAccessEvent> { protected void addRequestTime(long requestTime, Map<String, Object> map) { if (this.includeRequestTime && requestTime > 0) { final long sec = TimeUnit.MILLISECONDS.toSeconds(requestTime); final long ms = TimeUnit.MILLISECONDS.toMillis(requestTime - TimeUnit.SECONDS.toMillis(sec)); String time = String.format("%01d.%03d", sec, ms); if (time != null) { map.put(REQUESTTIME_ATTR_NAME, time); } } } JsonLayout(); boolean isIncludeRemoteAddr(); void setIncludeRemoteAddr(boolean includeRemoteAddr); boolean isIncludeRemoteUser(); void setIncludeRemoteUser(boolean includeRemoteUser); boolean isIncludeRequestTime(); void setIncludeRequestTime(boolean includeRequestTime); boolean isIncludeRequestURI(); void setIncludeRequestURI(boolean includeRequestURI); boolean isIncludeStatusCode(); void setIncludeStatusCode(boolean includeStatusCode); boolean isIncludeMethod(); void setIncludeMethod(boolean includeMethod); boolean isIncludeProtocol(); void setIncludeProtocol(boolean includeProtocol); boolean isIncludeContentLength(); void setIncludeContentLength(boolean includeContentLength); boolean isIncludeRequestURL(); void setIncludeRequestURL(boolean includeRequestURL); boolean isIncludeRemoteHost(); void setIncludeRemoteHost(boolean includeRemoteHost); boolean isIncludeServerName(); void setIncludeServerName(boolean includeServerName); boolean isIncludeRequestHeader(); void setIncludeRequestHeader(boolean includeRequestHeader); boolean isIncludeRequestParameter(); void setIncludeRequestParameter(boolean includeRequestParameter); boolean isIncludeLocalPort(); void setIncludeLocalPort(boolean includeLocalPort); boolean isIncludeRequestContent(); void setIncludeRequestContent(boolean includeRequestContent); boolean isIncludeResponseContent(); void setIncludeResponseContent(boolean includeResponseContent); static final String TIMESTAMP_ATTR_NAME; static final String REMOTEADDR_ATTR_NAME; static final String REMOTEUSER_ATTR_NAME; static final String REQUESTTIME_ATTR_NAME; static final String REQUESTURI_ATTR_NAME; static final String STATUSCODE_ATTR_NAME; static final String METHOD_ATTR_NAME; static final String PROTOCOL_ATTR_NAME; static final String CONTENTLENGTH_ATTR_NAME; static final String REQUESTURL_ATTR_NAME; static final String REMOTEHOST_ATTR_NAME; static final String SERVERNAME_ATTR_NAME; static final String REQUESTHEADER_ATTR_NAME; static final String REQUESTPARAMETER_ATTR_NAME; static final String LOCALPORT_ATTR_NAME; static final String REQUESTCONTENT_ATTR_NAME; static final String RESPONSECONTENT_ATTR_NAME; }
@Test public void addRequestTimeToJsonMap() throws Exception { Map<String, Object> map = new LinkedHashMap<String, Object>(); JsonLayout jsonLayout = new JsonLayout(); jsonLayout.addRequestTime(10001, map); assertThat(map.size(), is(1)); assertThat(map, hasKey(REQUESTTIME_ATTR_NAME)); assertEquals("10.001", map.get(REQUESTTIME_ATTR_NAME)); Map<String, Object> map2 = new LinkedHashMap<String, Object>(); JsonLayout jsonLayout2 = new JsonLayout(); jsonLayout2.addRequestTime(-1, map2); assertThat(map2.size(), is(0)); }