1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.commons.logging.log4j.log4j12;
19
20
21 import java.util.List;
22
23 import org.apache.commons.logging.log4j.StandardTests;
24 import org.apache.log4j.AppenderSkeleton;
25 import org.apache.log4j.spi.LoggingEvent;
26
27 /**
28 * A custom implementation of <code>org.apache.log4j.Appender</code> which
29 * converts the log4j-specific log event record into a representation that
30 * doesn't have a dependency on log4j and stores that new representation into
31 * an external list.
32 */
33
34 public class TestAppender extends AppenderSkeleton {
35
36 /**
37 * Constructor.
38 */
39 public TestAppender(List logEvents) {
40 events = logEvents;
41 }
42
43 // ----------------------------------------------------- Instance Variables
44
45
46 // The set of logged events for this appender
47 private List events;
48
49
50 // ------------------------------------------------------- Appender Methods
51
52 protected void append(LoggingEvent event) {
53 StandardTests.LogEvent lev = new StandardTests.LogEvent();
54
55 lev.level = event.getLevel().toString();
56
57 if (event.getMessage() == null)
58 lev.msg = null;
59 else
60 lev.msg = event.getMessage().toString();
61
62 if (event.getThrowableInformation() == null)
63 lev.throwable = null;
64 else
65 lev.throwable = event.getThrowableInformation().getThrowable();
66
67 events.add(lev);
68 }
69
70
71 public void close() {
72 }
73
74
75 public boolean requiresLayout() {
76 return (false);
77 }
78
79
80 }