1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package org.slf4j.impl;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  import java.util.Random;
15  
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  import ch.qos.logback.classic.PatternLayout;
20  import ch.qos.logback.classic.spi.LoggingEvent;
21  import ch.qos.logback.core.AppenderBase;
22  
23  public class RecursiveLBAppender extends AppenderBase<LoggingEvent> {
24  
25    public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
26    public List<String> stringList = new ArrayList<String>();
27    
28    PatternLayout layout;
29    
30    public RecursiveLBAppender() {
31      this(null);
32    }
33    
34    public RecursiveLBAppender(PatternLayout layout) {
35      this.layout = layout;
36    }
37    
38    @Override
39    public void start() {
40      int diff = new Random().nextInt();
41      Logger logger = LoggerFactory.getLogger("ResursiveLBAppender"+diff);
42      logger.info("testing");
43      super.start();
44    }
45    
46    protected void append(LoggingEvent e) {
47      list.add(e);
48      if(layout != null) {
49        String s = layout.doLayout(e);
50        stringList.add(s);
51      }
52    }
53  }