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