PageRenderTime 34ms CodeModel.GetById 20ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/apache-log4j-1.2.17/src/main/java/org/apache/log4j/lf5/DefaultLF5Configurator.java

#
Java | 123 lines | 29 code | 19 blank | 75 comment | 3 complexity | 8c3e6d5ca0528d80ab49318f45843112 MD5 | raw file
Possible License(s): Apache-2.0
  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
 18package org.apache.log4j.lf5;
 19
 20import java.io.IOException;
 21import java.io.InputStream;
 22import java.net.URL;
 23
 24import org.apache.log4j.PropertyConfigurator;
 25import org.apache.log4j.spi.Configurator;
 26import org.apache.log4j.spi.LoggerRepository;
 27
 28/**
 29 * The <code>DefaultLF5Configurator</code> provides a default
 30 * configuration for the <code>LF5Appender</code>.
 31 *
 32 * Note: The preferred method for configuring a <code>LF5Appender</code>
 33 * is to use the <code>LF5Manager</code> class. This class ensures
 34 * that configuration does not occur multiple times, and improves system
 35 * performance. Reconfiguring the monitor multiple times can result in
 36 * unexpected behavior.
 37 *
 38 * @author Brent Sprecher
 39 */
 40
 41// Contributed by ThoughtWorks Inc.
 42
 43public class DefaultLF5Configurator implements Configurator {
 44  //--------------------------------------------------------------------------
 45  // Constants:
 46  //--------------------------------------------------------------------------
 47
 48  //--------------------------------------------------------------------------
 49  // Protected Variables:
 50  //--------------------------------------------------------------------------
 51
 52  //--------------------------------------------------------------------------
 53  // Private Variables:
 54  //--------------------------------------------------------------------------
 55
 56  //--------------------------------------------------------------------------
 57  // Constructors:
 58  //--------------------------------------------------------------------------
 59  /**
 60   * This class should never be instantiated! It implements the <code>
 61   * Configurator</code>
 62   * interface, but does not provide the same functionality as full
 63   * configurator class.
 64   */
 65  private DefaultLF5Configurator() {
 66
 67  }
 68
 69  //--------------------------------------------------------------------------
 70  // Public Methods:
 71  //--------------------------------------------------------------------------
 72  /**
 73   * This method configures the <code>LF5Appender</code> using a
 74   * default configuration file. The default configuration file is
 75   * <bold>defaultconfig.properties</bold>.
 76   * @throws java.io.IOException
 77   */
 78  public static void configure() throws IOException {
 79    String resource =
 80        "/org/apache/log4j/lf5/config/defaultconfig.properties";
 81    URL configFileResource =
 82        DefaultLF5Configurator.class.getResource(resource);
 83
 84    if (configFileResource != null) {
 85      PropertyConfigurator.configure(configFileResource);
 86    } else {
 87      throw new IOException("Error: Unable to open the resource" +
 88          resource);
 89    }
 90
 91  }
 92
 93  /**
 94   * This is a dummy method that will throw an
 95   * <code>IllegalStateException</code> if used.
 96   * 
 97   * @since 1.2.17
 98   */
 99  public void doConfigure(InputStream inputStream, LoggerRepository repository) {
100    throw new IllegalStateException("This class should NOT be instantiated!");
101  }
102
103  /**
104   * This is a dummy method that will throw an
105   * <code>IllegalStateException</code> if used.
106   */
107  public void doConfigure(URL configURL, LoggerRepository repository) {
108    throw new IllegalStateException("This class should NOT be instantiated!");
109  }
110
111  //--------------------------------------------------------------------------
112  // Protected Methods:
113  //--------------------------------------------------------------------------
114
115  //--------------------------------------------------------------------------
116  // Private Methods:
117  //--------------------------------------------------------------------------
118
119  //--------------------------------------------------------------------------
120  // Nested Top-Level Classes or Interfaces:
121  //--------------------------------------------------------------------------
122
123}