@Override public void readConfiguration() throws IOException, SecurityException { checkAccess(); readConfiguration(Thread.currentThread().getContextClassLoader()); }
/** * Read configuration for the specified classloader. * * @param classLoader * @throws IOException Error */ protected void readConfiguration(ClassLoader classLoader) throws IOException { InputStream is = null; // Special case for URL classloaders which are used in containers: // only look in the local repositories to avoid redefining loggers 20 times try { if (classLoader instanceof URLClassLoader) { URL logConfig = ((URLClassLoader) classLoader).findResource("logging.properties"); if (null != logConfig) { if (Boolean.getBoolean(DEBUG_PROPERTY)) System.err.println( getClass().getName() + ".readConfiguration(): " + "Found logging.properties at " + logConfig); is = classLoader.getResourceAsStream("logging.properties"); } else { if (Boolean.getBoolean(DEBUG_PROPERTY)) System.err.println( getClass().getName() + ".readConfiguration(): " + "Found no logging.properties"); } } } catch (AccessControlException ace) { // No permission to configure logging in context // Log and carry on ClassLoaderLogManagerClassLoaderLogInfo info = classLoaderLoggers.get(ClassLoader.getSystemClassLoader()); if (info != null) { Logger log = info.getLoggers().get(""); if (log != null) { Permission perm = ace.getPermission(); if (perm instanceof FilePermission && perm.getActions().equals("read")) { log.warning( "Reading " + perm.getName() + " is not permitted. See \"per context logging\" in the default catalina.policy file."); } else { log.warning( "Reading logging.properties is not permitted in some context. See \"per context logging\" in the default catalina.policy file."); log.warning("Original error was: " + ace.getMessage()); } } } } if ((is == null) && (classLoader == ClassLoader.getSystemClassLoader())) { String configFileStr = System.getProperty("java.util.logging.config.file"); if (configFileStr != null) { try { is = new FileInputStream(replace(configFileStr)); } catch (IOException e) { // Ignore } } // Try the default JVM configuration if (is == null) { File defaultFile = new File(new File(System.getProperty("java.home"), "lib"), "logging.properties"); try { is = new FileInputStream(defaultFile); } catch (IOException e) { // Critical problem, do something ... } } } Logger localClassLoaderLogManagerRootLogger = new ClassLoaderLogManagerRootLogger(); if (is == null) { // Retrieve the root logger of the parent classloader instead ClassLoader current = classLoader.getParent(); ClassLoaderLogManagerClassLoaderLogInfo info = null; while (current != null && info == null) { info = getClassLoaderInfo(current); current = current.getParent(); } if (info != null) { localClassLoaderLogManagerRootLogger.setParent(info.getRootNode().getLogger()); } } ClassLoaderLogManagerClassLoaderLogInfo info = new ClassLoaderLogManagerClassLoaderLogInfo( new ClassLoaderLogManagerLogNode(null, localClassLoaderLogManagerRootLogger)); classLoaderLoggers.put(classLoader, info); if (is != null) { readConfiguration(is, classLoader); } addLogger(localClassLoaderLogManagerRootLogger); }