/** * Release any internal references to previously created * {@link org.apache.commons.logging.Log} * instances returned by this factory. This is useful in environments * like servlet containers, which implement application reloading by * throwing away a ClassLoader. Dangling references to objects in that * class loader would prevent garbage collection. */ public void release() { logDiagnostic("Releasing all known loggers"); instances.clear(); }
/** * Release any internal references to previously created * {@link org.apache.commons.logging.Log} * instances returned by this factory. This is useful in environments * like servlet containers, which implement application reloading by * throwing away a ClassLoader. Dangling references to objects in that * class loader would prevent garbage collection. */ public void release() { logDiagnostic("Releasing all known loggers"); instances.clear(); }
/** * Fetch the parent classloader of a specified classloader. * <p> * If a SecurityException occurs, null is returned. * <p> * Note that this method is non-static merely so logDiagnostic is available. */ private ClassLoader getParentClassLoader(final ClassLoader cl) { try { return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction() { public Object run() { return cl.getParent(); } }); } catch (SecurityException ex) { logDiagnostic("[SECURITY] Unable to obtain parent classloader"); return null; } }
logDiagnostic("setAttribute: call too late; configuration already performed.");
/** * Public no-arguments constructor required by the lookup mechanism. */ public LogFactoryImpl() { super(); initDiagnostics(); // method on this object if (isDiagnosticsEnabled()) { logDiagnostic("Instance created."); } }
logDiagnostic("Checking for '" + name + "'."); logDiagnostic("Did not find '" + name + "'."); logDiagnostic("Found '" + name + "'."); logDiagnostic("Logging system '" + name + "' is available but not useable.");
logDiagnostic("Could not instantiate Log '" + logAdapterClassName + "' -- " + discoveryFlaw.getClass().getName() + ": " + Throwable cause = ite.getTargetException(); if (cause != null) { logDiagnostic("... InvocationTargetException: " + cause.getClass().getName() + ": " + cause.getLocalizedMessage()); final StringWriter sw = new StringWriter(); cause2.printStackTrace(new PrintWriter(sw, true)); logDiagnostic("... ExceptionInInitializerError: " + sw.toString());
logDiagnostic("setAttribute: call too late; configuration already performed.");
logDiagnostic("[ENV] Trying to get configuration for item " + property); if (valueObj != null) { if (isDiagnosticsEnabled()) { logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property); logDiagnostic("[ENV] No LogFactory attribute found for " + property); if (value != null) { if (isDiagnosticsEnabled()) { logDiagnostic("[ENV] Found system property [" + value + "] for " + property); logDiagnostic("[ENV] No system property found for property " + property); logDiagnostic("[ENV] Security prevented reading system property " + property); logDiagnostic("[ENV] No configuration defined for item " + property);
/** * Public no-arguments constructor required by the lookup mechanism. */ public LogFactoryImpl() { super(); initDiagnostics(); // method on this object if (isDiagnosticsEnabled()) { logDiagnostic("Instance created."); } }
logDiagnostic("Checking for '" + name + "'."); logDiagnostic("Did not find '" + name + "'."); logDiagnostic("Found '" + name + "'."); logDiagnostic("Logging system '" + name + "' is available but not useable.");
/** * Generates an internal diagnostic logging of the discovery failure and * then throws a <code>LogConfigurationException</code> that wraps * the passed <code>Throwable</code>. * * @param logAdapterClassName is the class name of the Log implementation * that could not be instantiated. Cannot be <code>null</code>. * * @param classLoader is the classloader that we were trying to load the * logAdapterClassName from when the exception occurred. * * @param discoveryFlaw is the Throwable created by the classloader * * @throws LogConfigurationException ALWAYS */ private void handleFlawedDiscovery(String logAdapterClassName, ClassLoader classLoader, Throwable discoveryFlaw) { if (isDiagnosticsEnabled()) { logDiagnostic("Could not instantiate Log '" + logAdapterClassName + "' -- " + discoveryFlaw.getClass().getName() + ": " + discoveryFlaw.getLocalizedMessage()); } if (!allowFlawedDiscovery) { throw new LogConfigurationException(discoveryFlaw); } }
try { ClassLoader logInterfaceClassLoader = getClassLoader(Log.class); logDiagnostic("Class '" + badClass.getName() + "' was found in classloader " + objectId(badClassLoader) + ". It is bound to a Log interface which is not" + " the one loaded from classloader " + objectId(logInterfaceClassLoader)); } catch (Throwable t) { logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'"); msg.append("' visible."); if (isDiagnosticsEnabled()) { logDiagnostic(msg.toString()); msg.append(Log.class.getName()); msg.append("' visible."); logDiagnostic(msg.toString()); msg.append("' does not implement the Log interface."); if (isDiagnosticsEnabled()) { logDiagnostic(msg.toString()); msg.append(badClass.getName()); msg.append("' does not implement the Log interface."); logDiagnostic(msg.toString());
logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY + "'"); logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY_OLD + "'"); logDiagnostic("Trying to get log class from system property '" + LOG_PROPERTY + "'"); } catch (SecurityException e) { if (isDiagnosticsEnabled()) { logDiagnostic("No access allowed to system property '" + LOG_PROPERTY + "' - " + e.getMessage()); logDiagnostic("Trying to get log class from system property '" + LOG_PROPERTY_OLD + "'"); } catch (SecurityException e) { if (isDiagnosticsEnabled()) { logDiagnostic("No access allowed to system property '" + LOG_PROPERTY_OLD + "' - " + e.getMessage());
logDiagnostic("[ENV] Trying to get configuration for item " + property); if (valueObj != null) { if (isDiagnosticsEnabled()) { logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property); logDiagnostic("[ENV] No LogFactory attribute found for " + property); if (value != null) { if (isDiagnosticsEnabled()) { logDiagnostic("[ENV] Found system property [" + value + "] for " + property); logDiagnostic("[ENV] No system property found for property " + property); logDiagnostic("[ENV] Security prevented reading system property " + property); logDiagnostic("[ENV] No configuration defined for item " + property);
logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY + "'"); logDiagnostic("Trying to get log class from attribute '" + LOG_PROPERTY_OLD + "'"); logDiagnostic("Trying to get log class from system property '" + LOG_PROPERTY + "'"); } catch (SecurityException e) { if (isDiagnosticsEnabled()) { logDiagnostic("No access allowed to system property '" + LOG_PROPERTY + "' - " + e.getMessage()); logDiagnostic("Trying to get log class from system property '" + LOG_PROPERTY_OLD + "'"); } catch (SecurityException e) { if (isDiagnosticsEnabled()) { logDiagnostic("No access allowed to system property '" + LOG_PROPERTY_OLD + "' - " + e.getMessage());
logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'"); logDiagnostic("Trying to load '" + logAdapterClassName + "' from classloader " + objectId(currentCL)); try { if (isDiagnosticsEnabled()) { logDiagnostic("Class '" + logAdapterClassName + "' [" + resourceName + "] cannot be found."); } else { logDiagnostic("Class '" + logAdapterClassName + "' was found at '" + url + "'"); logDiagnostic("The log adapter '" + logAdapterClassName + "' is not available via classloader " + objectId(currentCL) + ": " + msg.trim()); try { logDiagnostic("The log adapter '" + logAdapterClassName + "' is not available via the LogFactoryImpl class classloader: " + msg.trim()); break; logDiagnostic("The log adapter '" + logAdapterClassName + "' is missing dependencies when loaded via classloader " + objectId(currentCL) + ": " + msg.trim()); logDiagnostic("The log adapter '" + logAdapterClassName + "' is unable to initialize itself when loaded via classloader " + objectId(currentCL) + ": " + msg.trim()); logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName + "'"); } catch (Throwable t) {
throws LogConfigurationException { if (isDiagnosticsEnabled()) { logDiagnostic("Discovering a Log implementation..."); logDiagnostic("Attempting to load user-specified log class '" + specifiedLogClassName + "'..."); logDiagnostic( "No user-specified Log implementation; performing discovery" + " using the standard supported logging implementations...");
logDiagnostic("[WARNING] the context classloader is not part of a" + " parent-child relationship with the classloader that" + " loaded LogFactoryImpl."); logDiagnostic( "Warning: the context classloader is an ancestor of the" + " classloader that loaded LogFactoryImpl; it should be" +
logDiagnostic("Discovering a Log implementation..."); logDiagnostic("Attempting to load user-specified log class '" + specifiedLogClassName + "'..."); logDiagnostic( "No user-specified Log implementation; performing discovery" + " using the standard supported logging implementations...");