private IAccessEvent mockBasicILoggingEvent() {
   IAccessEvent event = mock(IAccessEvent.class);
   when(event.getContentLength()).thenReturn(123L);
   when(event.getMethod()).thenReturn("GET");
   when(event.getProtocol()).thenReturn("HTTPS");
   when(event.getRemoteHost()).thenReturn("123.123.123.123");
   when(event.getRemoteUser()).thenReturn("remote-user");
   when(event.getRequestURI()).thenReturn("/my/uri");
   when(event.getRequestURL()).thenReturn("https://123.123.123.123/my/uri");
   when(event.getStatusCode()).thenReturn(200);
   when(event.getTimeStamp()).thenReturn(System.currentTimeMillis());
   return event;
 }
 public Serializable transform(IAccessEvent event) {
   if (event instanceof AccessEvent) {
     return (AccessEvent) event;
   } else {
     throw new IllegalArgumentException("Unsupported type " + event.getClass().getName());
   }
 }
  public String convert(IAccessEvent accessEvent) {

    String user = accessEvent.getRemoteUser();
    if (user == null) {
      return IAccessEvent.NA;
    } else {
      return user;
    }
  }
  @Override
  public String convert(IAccessEvent accessEvent) {
    if (!isStarted()) {
      return "INACTIVE_REQUEST_PARAM_CONV";
    }

    String[] paramArray = accessEvent.getRequestParameter(key);
    if (paramArray.length == 1) {
      return paramArray[0];
    } else {
      // for an array string {"a", "b"} named 'sa', Array.toString(sa) returns the string
      // "[a, b]".
      return Arrays.toString(paramArray);
    }
  }
 @Override
 public void writeTo(JsonGenerator generator, IAccessEvent event) throws IOException {
   JsonWritingUtils.writeMapStringFields(
       generator, getFieldName(), event.getResponseHeaderMap(), lowerCaseHeaderNames);
 }
 @Override
 public String convert(IAccessEvent accessEvent) {
   return accessEvent.getRemoteHost();
 }
 @Override
 protected void postProcessEvent(IAccessEvent event) {
   event.prepareForDeferredProcessing();
 }
 @Override
 public String convert(IAccessEvent accessEvent) {
   return Integer.toString(accessEvent.getLocalPort());
 }
  @Test
  public void basicsAreIncluded() throws Exception {
    final long timestamp = System.currentTimeMillis();

    IAccessEvent event = mockBasicILoggingEvent();
    when(event.getTimeStamp()).thenReturn(timestamp);

    encoder.doEncode(event);
    closeQuietly(outputStream);

    JsonNode node = MAPPER.readTree(outputStream.toByteArray());

    assertThat(
        node.get("@timestamp").textValue(),
        is(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ").format(timestamp)));
    assertThat(node.get("@version").intValue(), is(1));
    assertThat(
        node.get("@message").textValue(),
        is(
            String.format(
                "%s - %s [%s] \"%s\" %s %s",
                event.getRemoteHost(),
                event.getRemoteUser(),
                FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZZ")
                    .format(event.getTimeStamp()),
                event.getRequestURL(),
                event.getStatusCode(),
                event.getContentLength())));

    assertThat(node.get("@fields.method").textValue(), is(event.getMethod()));
    assertThat(node.get("@fields.protocol").textValue(), is(event.getProtocol()));
    assertThat(node.get("@fields.status_code").asInt(), is(event.getStatusCode()));
    assertThat(node.get("@fields.requested_url").textValue(), is(event.getRequestURL()));
    assertThat(node.get("@fields.requested_uri").textValue(), is(event.getRequestURI()));
    assertThat(node.get("@fields.remote_host").textValue(), is(event.getRemoteHost()));
    assertThat(node.get("@fields.HOSTNAME").textValue(), is(event.getRemoteHost()));
    assertThat(node.get("@fields.remote_user").textValue(), is(event.getRemoteUser()));
    assertThat(node.get("@fields.content_length").asLong(), is(event.getContentLength()));
  }
 public String convert(IAccessEvent accessEvent) {
   long timestamp = accessEvent.getTimeStamp();
   return cachingDateFormatter.format(timestamp);
 }