/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.aspects.logging;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

import java.util.ArrayList;

/**
 * An appender that logs into a thread local array list.
 *
 * @author  <a href="mailto:adrian@jboss.org">Adrian Brock</a>.
 * @version $Revision: 1.2.2.3 $
 */
public class ThreadLocalAppender
   extends AppenderSkeleton
{
   // Constants -----------------------------------------------------

   public static final String LOG = "InvocationLog";

   private static ThreadLocal loggingTL = new ThreadLocal(); 

   // Attributes ----------------------------------------------------

   // Static --------------------------------------------------------

   /**
    * Change the theadlocal list
    * 
    * @param list the new list
    */
   public static ArrayList getList()
   {
      return (ArrayList) loggingTL.get();
   }

   /**
    * Change the theadlocal list
    * 
    * @param list the new list
    */
   public static void setList(ArrayList list)
   {
      loggingTL.set(list);
   }

   // Constructors --------------------------------------------------

   // Public --------------------------------------------------------

   // Appender Implementation ---------------------------------------

   protected void append(LoggingEvent event)
   {
      ArrayList logging = getList();
      if (logging == null)
         return;

      logging.add(event);
   }

   public boolean requiresLayout()
   {
      return false;
   }

   public void close()
   {
   }

   // Y Overrides ---------------------------------------------------

   // Protected -----------------------------------------------------

   // Private -------------------------------------------------------

   // Inner Classes -------------------------------------------------
}
