View Javadoc
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  package org.apache.log4j.builders.appender;
18  
19  import org.apache.log4j.Appender;
20  import org.apache.log4j.bridge.AppenderWrapper;
21  import org.apache.log4j.config.PropertiesConfiguration;
22  import org.apache.log4j.xml.XmlConfiguration;
23  import org.apache.logging.log4j.Logger;
24  import org.apache.logging.log4j.core.appender.NullAppender;
25  import org.apache.logging.log4j.core.config.plugins.Plugin;
26  import org.apache.logging.log4j.status.StatusLogger;
27  import org.w3c.dom.Element;
28  
29  import java.util.Properties;
30  
31  import static org.apache.log4j.builders.BuilderManager.CATEGORY;
32  
33  /**
34   * Build a Null Appender
35   */
36  @Plugin(name = "org.apache.log4j.varia.NullAppender", category = CATEGORY)
37  public class NullAppenderBuilder implements AppenderBuilder {
38  
39      private static final Logger LOGGER = StatusLogger.getLogger();
40  
41      @Override
42      public Appender parseAppender(Element appenderElement, XmlConfiguration config) {
43          String name = appenderElement.getAttribute("name");
44          return new AppenderWrapper(NullAppender.createAppender(name));
45      }
46  
47  
48      @Override
49      public Appender parseAppender(final String name, final String appenderPrefix, final String layoutPrefix,
50              final String filterPrefix, final Properties props, final PropertiesConfiguration configuration) {
51          return new AppenderWrapper(NullAppender.createAppender(name));
52      }
53  }