01: /*
02: * Copyright 2005 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import java.util.List;
20:
21: import org.apache.commons.logging.log4j.StandardTests;
22: import org.apache.log4j.AppenderSkeleton;
23: import org.apache.log4j.spi.LoggingEvent;
24:
25: /**
26: * A custom implementation of <code>org.apache.log4j.Appender</code> which
27: * converts the log4j-specific log event record into a representation that
28: * doesn't have a dependency on log4j and stores that new representation into
29: * an external list.
30: */
31:
32: public class TestAppender extends AppenderSkeleton {
33:
34: /**
35: * Constructor.
36: */
37: public TestAppender(List logEvents) {
38: events = logEvents;
39: }
40:
41: // ----------------------------------------------------- Instance Variables
42:
43: // The set of logged events for this appender
44: private List events;
45:
46: // ------------------------------------------------------- Appender Methods
47:
48: protected void append(LoggingEvent event) {
49: StandardTests.LogEvent lev = new StandardTests.LogEvent();
50:
51: lev.level = event.getLevel().toString();
52:
53: if (event.getMessage() == null)
54: lev.msg = null;
55: else
56: lev.msg = event.getMessage().toString();
57:
58: if (event.getThrowableInformation() == null)
59: lev.throwable = null;
60: else
61: lev.throwable = event.getThrowableInformation()
62: .getThrowable();
63:
64: events.add(lev);
65: }
66:
67: public void close() {
68: }
69:
70: public boolean requiresLayout() {
71: return (false);
72: }
73:
74: }
|