KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > logging > log4j > log4j12 > TestAppender


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.logging.log4j.log4j12;
18
19
20 import java.util.List JavaDoc;
21
22 import org.apache.commons.logging.log4j.StandardTests;
23 import org.apache.log4j.AppenderSkeleton;
24 import org.apache.log4j.spi.LoggingEvent;
25
26 /**
27  * A custom implementation of <code>org.apache.log4j.Appender</code> which
28  * converts the log4j-specific log event record into a representation that
29  * doesn't have a dependency on log4j and stores that new representation into
30  * an external list.
31  */

32
33 public class TestAppender extends AppenderSkeleton {
34
35     /**
36      * Constructor.
37      */

38     public TestAppender(List JavaDoc logEvents) {
39         events = logEvents;
40     }
41
42     // ----------------------------------------------------- Instance Variables
43

44
45     // The set of logged events for this appender
46
private List JavaDoc events;
47
48
49     // ------------------------------------------------------- Appender Methods
50

51     protected void append(LoggingEvent event) {
52         StandardTests.LogEvent lev = new StandardTests.LogEvent();
53         
54         lev.level = event.getLevel().toString();
55
56         if (event.getMessage() == null)
57             lev.msg = null;
58         else
59             lev.msg = event.getMessage().toString();
60         
61         if (event.getThrowableInformation() == null)
62             lev.throwable = null;
63         else
64             lev.throwable = event.getThrowableInformation().getThrowable();
65
66         events.add(lev);
67     }
68
69
70     public void close() {
71     }
72
73
74     public boolean requiresLayout() {
75         return (false);
76     }
77
78
79 }
80
Popular Tags