KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aspects > logging > ThreadLocalAppender


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aspects.logging;
23
24 import org.apache.log4j.AppenderSkeleton;
25 import org.apache.log4j.spi.LoggingEvent;
26
27 import java.util.ArrayList JavaDoc;
28
29 /**
30  * An appender that logs into a thread local array list.
31  *
32  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>.
33  * @version $Revision: 37406 $
34  */

35 public class ThreadLocalAppender
36    extends AppenderSkeleton
37 {
38    // Constants -----------------------------------------------------
39

40    public static final String JavaDoc LOG = "InvocationLog";
41
42    private static ThreadLocal JavaDoc loggingTL = new ThreadLocal JavaDoc();
43
44    // Attributes ----------------------------------------------------
45

46    // Static --------------------------------------------------------
47

48    /**
49     * Change the theadlocal list
50     *
51     * @param list the new list
52     */

53    public static ArrayList JavaDoc getList()
54    {
55       return (ArrayList JavaDoc) loggingTL.get();
56    }
57
58    /**
59     * Change the theadlocal list
60     *
61     * @param list the new list
62     */

63    public static void setList(ArrayList JavaDoc list)
64    {
65       loggingTL.set(list);
66    }
67
68    // Constructors --------------------------------------------------
69

70    // Public --------------------------------------------------------
71

72    // Appender Implementation ---------------------------------------
73

74    protected void append(LoggingEvent event)
75    {
76       ArrayList JavaDoc logging = getList();
77       if (logging == null)
78          return;
79
80       logging.add(event);
81    }
82
83    public boolean requiresLayout()
84    {
85       return false;
86    }
87
88    public void close()
89    {
90    }
91
92    // Y Overrides ---------------------------------------------------
93

94    // Protected -----------------------------------------------------
95

96    // Private -------------------------------------------------------
97

98    // Inner Classes -------------------------------------------------
99
}
100
Popular Tags