public void log(LogRecord record) {
    if (logToFile != null) {
      logToFile(record);
    }

    if (ignoreLogging) return;

    CapedwarfRequestLogs requestLogs = getCurrentRequestLogs();
    if (requestLogs != null) {
      CapedwarfAppLogLine capedwarfAppLogLine =
          new CapedwarfAppLogLine(getCurrentRequestId(), record.getSequenceNumber());
      AppLogLine appLogLine = capedwarfAppLogLine.getAppLogLine();
      appLogLine.setLogLevel(getLogLevel(record));
      appLogLine.setLogMessage(
          record.getSourceClassName()
              + " "
              + record.getSourceMethodName()
              + ": "
              + getFormattedMessage(record)
              + "\n");
      appLogLine.setTimeUsec(record.getMillis() * 1000);
      logWriter.put(capedwarfAppLogLine);

      requestLogs.logLineAdded(appLogLine);
      logWriter.put(requestLogs);
    }
  }
 public void requestFinished(ServletRequest servletRequest, int status, int contentLength) {
   CapedwarfRequestLogs capedwarfRequestLogs = getCapedwarfRequestLogs(servletRequest);
   // check if all went well
   if (capedwarfRequestLogs != null) {
     RequestLogs requestLogs = capedwarfRequestLogs.getRequestLogs();
     requestLogs.setEndTimeUsec(System.currentTimeMillis() * 1000);
     requestLogs.setStatus(status);
     requestLogs.setResponseSize(contentLength);
     requestLogs.setFinished(true);
     logWriter.put(capedwarfRequestLogs);
   }
 }
  public void requestStarted(ServletRequest servletRequest, long startTimeMillis) {
    if (ignoreLogging || !isLoggable(servletRequest)) {
      return;
    }

    CapedwarfEnvironment environment = CapedwarfEnvironment.getThreadLocalInstance();
    CapedwarfRequestLogs capedwarfRequestLogs =
        createCapedwarfRequestLogs(servletRequest, startTimeMillis, environment);

    logWriter.put(capedwarfRequestLogs);
    servletRequest.setAttribute(REQUEST_LOGS_REQUEST_ATTRIBUTE, capedwarfRequestLogs);
    environment.getAttributes().put(REQUEST_LOGS_ENV_ATTRIBUTE, capedwarfRequestLogs);
    environment
        .getAttributes()
        .put(REQUEST_LOG_ID, capedwarfRequestLogs.getRequestLogs().getRequestId());
  }