1 22 package org.jboss.logging.jdk; 23 24 import java.util.logging.LogManager ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.FileInputStream ; 28 import java.io.BufferedInputStream ; 29 import java.io.FileNotFoundException ; 30 import java.io.File ; 31 import java.net.URL ; 32 import org.jboss.logging.jdk.xml.DOMConfigurator; 33 34 38 public class JDKLogManager extends LogManager 39 { 40 private static final String DEFAULT_CONFIG_PROPS = "jdklogger.properties"; 41 private static final String DEFAULT_CONFIG_XML = "jdklogger.xml"; 42 43 public JDKLogManager() 44 { 45 } 46 47 59 public void readConfiguration() 60 throws IOException , SecurityException 61 { 62 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 63 String config = SecurityActions.getProperty("java.util.logging.config.file"); 64 URL configURL = null; 65 if( config == null ) 66 { 67 config = DEFAULT_CONFIG_XML; 69 configURL = loader.getResource(DEFAULT_CONFIG_XML); 70 if( configURL == null ) 71 { 72 config = DEFAULT_CONFIG_PROPS; 73 configURL = loader.getResource(DEFAULT_CONFIG_PROPS); 74 } 75 76 if( configURL == null ) 78 { 79 config = DEFAULT_CONFIG_XML; 80 File test = new File (DEFAULT_CONFIG_XML); 81 if( test.exists() == true ) 82 configURL = test.toURL(); 83 else 84 { 85 config = DEFAULT_CONFIG_PROPS; 86 test = new File (DEFAULT_CONFIG_PROPS); 87 if( test.exists() == true ) 88 configURL = test.toURL(); 89 } 90 if( configURL == null ) 92 { 93 String msg = "No java.util.logging.config.file specified, and neither the default " 94 + DEFAULT_CONFIG_XML + " or " + DEFAULT_CONFIG_PROPS + " was found"; 95 throw new FileNotFoundException (msg); 96 } 97 } 98 } 99 100 if( configURL == null ) 102 configURL = loader.getResource(config); 103 InputStream is = null; 104 if( configURL == null ) 105 { 106 InputStream in = new FileInputStream (config); 108 is = new BufferedInputStream (in); 109 } 110 else 111 { 112 is = configURL.openStream(); 114 } 115 116 boolean isXML = config.endsWith(".xml"); 118 try 119 { 120 if( isXML ) 121 { 122 DOMConfigurator.configure(is); 123 } 124 else 125 { 126 super.readConfiguration(is); 128 } 129 } 130 finally 131 { 132 if( is != null ) 133 is.close(); 134 } 135 } 136 137 145 public void reset() 146 { 147 } 148 149 152 public void doReset() 153 { 154 super.reset(); 155 } 156 } 157 158 | Popular Tags |