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  
18  package org.apache.log4j.lf5;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.net.URL;
23  
24  import org.apache.log4j.PropertyConfigurator;
25  import org.apache.log4j.spi.Configurator;
26  import 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  
43  public 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 }