content: /*
   * Copyright The OpenTelemetry Authors
   * SPDX-License-Identifier: Apache-2.0
   */
  
  package io.opentelemetry.instrumentation.logback.mdc.v1_0;
  
  import ch.qos.logback.classic.spi.ILoggingEvent;
  import ch.qos.logback.core.Appender;
  import ch.qos.logback.core.UnsynchronizedAppenderBase;
  import ch.qos.logback.core.spi.AppenderAttachable;
  import ch.qos.logback.core.spi.AppenderAttachableImpl;
  import java.util.Iterator;
  
  public class TestAppender extends UnsynchronizedAppenderBase<ILoggingEvent>
      implements AppenderAttachable<ILoggingEvent> {
  
    static TestAppender instance;
    private final AppenderAttachableImpl<ILoggingEvent> aai = new AppenderAttachableImpl<>();
    ILoggingEvent lastEvent;
  
    public TestAppender() {
      instance = this;
    }
  
    private void processEvent(ILoggingEvent event) {
      lastEvent = event;
    }
  
    @Override
    protected void append(ILoggingEvent event) {
      processEvent(event);
      aai.appendLoopOnAppenders(event);
    }
  
    @Override
    public void addAppender(Appender<ILoggingEvent> appender) {
      aai.addAppender(appender);
    }
  
    @Override
    public Iterator<Appender<ILoggingEvent>> iteratorForAppenders() {
      return aai.iteratorForAppenders();
    }
  
    @Override
    public Appender<ILoggingEvent> getAppender(String name) {
      return aai.getAppender(name);
    }
  
    @Override
    public boolean isAttached(Appender<ILoggingEvent> appender) {
      return aai.isAttached(appender);
    }
  
    @Override
    public void detachAndStopAllAppenders() {
      aai.detachAndStopAllAppenders();
    }
  
    @Override
    public boolean detachAppender(Appender<ILoggingEvent> appender) {
      return aai.detachAppender(appender);
    }
  
    @Override
    public boolean detachAppender(String name) {
      return aai.detachAppender(name);
    }
  }
  