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
018package org.apache.log4j.lf5;
019
020import java.io.IOException;
021import java.io.InputStream;
022import java.net.URL;
023
024import org.apache.log4j.PropertyConfigurator;
025import org.apache.log4j.spi.Configurator;
026import org.apache.log4j.spi.LoggerRepository;
027
028/**
029 * The <code>DefaultLF5Configurator</code> provides a default
030 * configuration for the <code>LF5Appender</code>.
031 *
032 * Note: The preferred method for configuring a <code>LF5Appender</code>
033 * is to use the <code>LF5Manager</code> class. This class ensures
034 * that configuration does not occur multiple times, and improves system
035 * performance. Reconfiguring the monitor multiple times can result in
036 * unexpected behavior.
037 *
038 * @author Brent Sprecher
039 */
040
041// Contributed by ThoughtWorks Inc.
042
043public class DefaultLF5Configurator implements Configurator {
044  //--------------------------------------------------------------------------
045  // Constants:
046  //--------------------------------------------------------------------------
047
048  //--------------------------------------------------------------------------
049  // Protected Variables:
050  //--------------------------------------------------------------------------
051
052  //--------------------------------------------------------------------------
053  // Private Variables:
054  //--------------------------------------------------------------------------
055
056  //--------------------------------------------------------------------------
057  // Constructors:
058  //--------------------------------------------------------------------------
059  /**
060   * This class should never be instantiated! It implements the <code>
061   * Configurator</code>
062   * interface, but does not provide the same functionality as full
063   * configurator class.
064   */
065  private DefaultLF5Configurator() {
066
067  }
068
069  //--------------------------------------------------------------------------
070  // Public Methods:
071  //--------------------------------------------------------------------------
072  /**
073   * This method configures the <code>LF5Appender</code> using a
074   * default configuration file. The default configuration file is
075   * <bold>defaultconfig.properties</bold>.
076   * @throws java.io.IOException
077   */
078  public static void configure() throws IOException {
079    String resource =
080        "/org/apache/log4j/lf5/config/defaultconfig.properties";
081    URL configFileResource =
082        DefaultLF5Configurator.class.getResource(resource);
083
084    if (configFileResource != null) {
085      PropertyConfigurator.configure(configFileResource);
086    } else {
087      throw new IOException("Error: Unable to open the resource" +
088          resource);
089    }
090
091  }
092
093  /**
094   * This is a dummy method that will throw an
095   * <code>IllegalStateException</code> if used.
096   * 
097   * @since 1.2.17
098   */
099  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}