001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.logging.log4j.log4j12; 019 020 021 import java.util.List; 022 023 import org.apache.commons.logging.log4j.StandardTests; 024 import org.apache.log4j.AppenderSkeleton; 025 import org.apache.log4j.spi.LoggingEvent; 026 027 /** 028 * A custom implementation of <code>org.apache.log4j.Appender</code> which 029 * converts the log4j-specific log event record into a representation that 030 * doesn't have a dependency on log4j and stores that new representation into 031 * an external list. 032 */ 033 034 public class TestAppender extends AppenderSkeleton { 035 036 /** 037 * Constructor. 038 */ 039 public TestAppender(List logEvents) { 040 events = logEvents; 041 } 042 043 // ----------------------------------------------------- Instance Variables 044 045 046 // The set of logged events for this appender 047 private List events; 048 049 050 // ------------------------------------------------------- Appender Methods 051 052 protected void append(LoggingEvent event) { 053 StandardTests.LogEvent lev = new StandardTests.LogEvent(); 054 055 lev.level = event.getLevel().toString(); 056 057 if (event.getMessage() == null) 058 lev.msg = null; 059 else 060 lev.msg = event.getMessage().toString(); 061 062 if (event.getThrowableInformation() == null) 063 lev.throwable = null; 064 else 065 lev.throwable = event.getThrowableInformation().getThrowable(); 066 067 events.add(lev); 068 } 069 070 071 public void close() { 072 } 073 074 075 public boolean requiresLayout() { 076 return (false); 077 } 078 079 080 }