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.logging.log4j.core.config;
    18
    19  import org.apache.logging.log4j.Level;
    20  import org.apache.logging.log4j.Logger;
    21  import org.apache.logging.log4j.core.Filter;
    22  import org.apache.logging.log4j.core.config.plugins.Plugin;
    23  import org.apache.logging.log4j.core.config.plugins.PluginAliases;
    24  import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
    25  import org.apache.logging.log4j.core.config.plugins.PluginElement;
    26  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
    27  import org.apache.logging.log4j.status.StatusLogger;
    28
    29  /**
    30   * An Appender reference.
    31   */
    32  @Plugin(name = "AppenderRef", category = Node.CATEGORY, printObject = true)
    33  @PluginAliases("appender-ref")
    34  public final class AppenderRef {
    35      private static final Logger LOGGER = StatusLogger.getLogger();
    36
    37      private final String ref;
    38      private final Level level;
    39      private final Filter filter;
    40
    41      private AppenderRef(final String ref, final Level level, final Filter filter) {
    42          this.ref = ref;
    43          this.level = level;
    44          this.filter = filter;
    45      }
    46
    47      public String getRef() {
    48          return ref;
    49      }
    50
    51      public Level getLevel() {
    52          return level;
    53      }
    54
    55      public Filter getFilter() {
    56          return filter;
    57      }
    58
    59      @Override
    60      public String toString() {
    61          return ref;
    62      }
    63
    64      /**
    65       * Create an Appender reference.
    66       * @param ref The name of the Appender.
    67       * @param level The Level to filter against.
    68       * @param filter The filter(s) to use.
    69       * @return The name of the Appender.
    70       */
    71      @PluginFactory
    72      public static AppenderRef createAppenderRef(
    73              @PluginAttribute("ref") final String ref,
    74              @PluginAttribute("level") final Level level,
    75              @PluginElement("Filter") final Filter filter) {
    76
    77          if (ref == null) {
    78              LOGGER.error("Appender references must contain a reference");
    79              return null;
    80          }
    81          return new AppenderRef(ref, level, filter);
    82      }
    83  }