View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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 org.slf4j.impl;
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.PatternLayout;
23  import ch.qos.logback.classic.spi.ILoggingEvent;
24  import ch.qos.logback.core.AppenderBase;
25  import ch.qos.logback.core.testUtil.RandomUtil;
26  
27  public class RecursiveLBAppender extends AppenderBase<ILoggingEvent> {
28  
29      public List<ILoggingEvent> list = new ArrayList<ILoggingEvent>();
30      public List<String> stringList = new ArrayList<String>();
31  
32      PatternLayout layout;
33  
34      public RecursiveLBAppender() {
35          this(null);
36      }
37  
38      public RecursiveLBAppender(PatternLayout layout) {
39          this.layout = layout;
40      }
41  
42      @Override
43      public void start() {
44          int diff = RandomUtil.getPositiveInt();
45          Logger logger = LoggerFactory.getLogger("ResursiveLBAppender" + diff);
46          logger.info("testing");
47          super.start();
48      }
49  
50      protected void append(ILoggingEvent e) {
51          list.add(e);
52          if (layout != null) {
53              String s = layout.doLayout(e);
54              stringList.add(s);
55          }
56      }
57  }