@Override
  protected void subAppend(LoggingEvent event) {
    if (printNow) {
      super.subAppend(event);
    } else {
      // set name of current thread on the event so it's correct when/if we print the message later
      event.getThreadName();

      if (gatewayName != null) {
        injectGatewayName(event);
      }
      eventsList.add(event);
      // To avoid OOM, limit number of cached messages
      if (messageCount.incrementAndGet() > MAX_MESSAGES) {
        eventsList.poll(); // remove oldest message
      }
    }
  }
 private void injectGatewayName(LoggingEvent event) {
   if (!injectGatewayName(event, "renderedMessage")) {
     injectGatewayName(event, "message");
   }
 }