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