protected void failSafeConfigure()

in src/main/java/org/apache/sling/commons/log/logback/internal/LogConfigManager.java [1435:1499]


    protected void failSafeConfigure() {
        try {
            addInfo("Performing configuration");

            long startTime = System.currentTimeMillis();
            StatusListener statusListener = new StatusListenerAsList() {
                @Override
                public boolean isResetResistant() {
                    // ensure that after a reset the statusListenerAsList does not get
                    // removed as a listener
                    return true;
                }
            };
            if (debug) {
                OnConsoleStatusListener onConsoleStatusListener = new OnConsoleStatusListener();
                // ensure that after a reset the statusListenerAsList does not get
                // removed as a listener
                onConsoleStatusListener.setResetResistant(true);
                statusListener = onConsoleStatusListener;
            }

            getStatusManager().add(statusListener);
            addInfo("Resetting context: " + getLoggerContext().getName());

            JoranConfigurator configurator = new JoranConfiguratorWrapper(this);
            configurator.setContext(loggerContext);
            final Model failsafeTop = configurator.recallSafeConfiguration();

            loggerContext.reset();

            final long threshold = System.currentTimeMillis();
            boolean success = false;
            try {
                if (logbackConfigFile != null) {
                    // use the configured file
                    configurator.doConfigure(logbackConfigFile);
                } else {
                    // fallback to the empty configuration
                    configurator.doConfigure(getDefaultConfigURL());
                }

                // e.g. IncludeAction will add a status regarding XML parsing errors but no exception will reach here
                StatusUtil statusUtil = new StatusUtil(loggerContext);
                if (!statusUtil.hasXMLParsingErrors(threshold)) {
                    addInfo("Context: " + getLoggerContext().getName() + " reloaded.");
                    success = true;
                }
            } catch (Throwable t) { // NOSONAR
                // Need to catch any error as Logback must work in all scenarios
                // The error would be dumped to sysout in later call to Status printer
                addError("Error occurred while configuring Logback", t);
            } finally {
                if (!success) {
                    fallbackConfiguration(loggerContext, failsafeTop);
                }
                getStatusManager().remove(statusListener);
                SlingStatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext, resetStartTime, startTime, success);
            }

            fireResetCompleteListeners();
        } catch (Exception e) {
            logger.warn("Error occurred while re-configuring logger", e);
            addError("Error occurred while re-configuring logger", e);
        }
    }