View Javadoc
1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import org.slf4j.Logger;
20  import org.slf4j.LoggerFactory;
21  
22  import ch.qos.logback.classic.spi.ILoggingEvent;
23  import ch.qos.logback.core.AppenderBase;
24  import ch.qos.logback.core.testUtil.RandomUtil;
25  
26  public class RecursiveLBAppender extends AppenderBase<ILoggingEvent> {
27  
28      public List<ILoggingEvent> list = new ArrayList<ILoggingEvent>();
29      public List<String> stringList = new ArrayList<String>();
30  
31      PatternLayout layout;
32  
33      public RecursiveLBAppender() {
34          this(null);
35      }
36  
37      public RecursiveLBAppender(PatternLayout layout) {
38          this.layout = layout;
39      }
40  
41      @Override
42      public void start() {
43          int diff = RandomUtil.getPositiveInt();
44          Logger logger = LoggerFactory.getLogger("ResursiveLBAppender" + diff);
45          logger.info("testing");
46          super.start();
47      }
48  
49      protected void append(ILoggingEvent e) {
50          list.add(e);
51          if (layout != null) {
52              String s = layout.doLayout(e);
53              stringList.add(s);
54          }
55      }
56  }