Search in sources :

Example 1 with SaxEvent

use of ch.qos.logback.core.joran.event.SaxEvent in project sling by apache.

the class LogbackManager method configure.

private void configure(ConfiguratorCallback cb) {
    long startTime = System.currentTimeMillis();
    StatusListener statusListener = new StatusListenerAsList();
    if (debug) {
        statusListener = new OnConsoleStatusListener();
    }
    getStatusManager().add(statusListener);
    addInfo("Resetting context: " + getLoggerContext().getName());
    resetContext(statusListener);
    StatusUtil statusUtil = new StatusUtil(getLoggerContext());
    JoranConfigurator configurator = createConfigurator();
    final List<SaxEvent> eventList = configurator.recallSafeConfiguration();
    final long threshold = System.currentTimeMillis();
    boolean success = false;
    try {
        cb.perform(configurator);
        if (statusUtil.hasXMLParsingErrors(threshold)) {
            cb.fallbackConfiguration(eventList, createConfigurator(), statusListener);
        }
        addInfo("Context: " + getLoggerContext().getName() + " reloaded.");
        success = true;
    } catch (Throwable t) {
        //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) {
            cb.fallbackConfiguration(eventList, createConfigurator(), statusListener);
        }
        getStatusManager().remove(statusListener);
        SlingStatusPrinter.printInCaseOfErrorsOrWarnings(getLoggerContext(), resetStartTime, startTime, success);
    }
}
Also used : JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) SaxEvent(ch.qos.logback.core.joran.event.SaxEvent) OnConsoleStatusListener(ch.qos.logback.core.status.OnConsoleStatusListener) StatusListener(ch.qos.logback.core.status.StatusListener) OnConsoleStatusListener(ch.qos.logback.core.status.OnConsoleStatusListener) StatusListenerAsList(ch.qos.logback.core.status.StatusListenerAsList) StatusUtil(ch.qos.logback.core.status.StatusUtil)

Example 2 with SaxEvent

use of ch.qos.logback.core.joran.event.SaxEvent in project sling by apache.

the class OsgiInternalAction method trimHeadAndTail.

private static void trimHeadAndTail(SaxEventRecorder recorder) {
    // Let's remove the two <included> events before
    // adding the events to the player.
    List<SaxEvent> saxEventList = recorder.saxEventList;
    if (saxEventList.size() == 0) {
        return;
    }
    SaxEvent first = saxEventList.get(0);
    if (first != null && first.qName.equalsIgnoreCase(INCLUDED_TAG)) {
        saxEventList.remove(0);
    }
    SaxEvent last = saxEventList.get(recorder.saxEventList.size() - 1);
    if (last != null && last.qName.equalsIgnoreCase(INCLUDED_TAG)) {
        saxEventList.remove(recorder.saxEventList.size() - 1);
    }
}
Also used : SaxEvent(ch.qos.logback.core.joran.event.SaxEvent)

Example 3 with SaxEvent

use of ch.qos.logback.core.joran.event.SaxEvent in project sling by apache.

the class OsgiInternalAction method begin.

@SuppressWarnings("unchecked")
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
    ec.addInPlayListener(new ConfigCompleteListener(ec));
    populateSubstitutionProperties(ec);
    // TO CHECK Should we add the config fragment at end
    final Collection<ConfigSourceInfo> providers = getFragmentProviders();
    List<SaxEvent> consolidatedEventList = new ArrayList<SaxEvent>();
    for (ConfigSourceInfo cp : providers) {
        InputSource is = cp.getConfigProvider().getConfigSource();
        try {
            SaxEventRecorder recorder = new SaxEventRecorder(context);
            recorder.recordEvents(is);
            // remove the <included> tag from the beginning and </included>
            // from the end
            trimHeadAndTail(recorder);
            consolidatedEventList.addAll(recorder.getSaxEventList());
        } catch (JoranException e) {
            addError("Error while parsing xml obtained from  [" + cp + "]", e);
        } finally {
            Util.close(is);
        }
    }
    // offset = 2, because we need to get past this element as well as the
    // end element
    ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(consolidatedEventList, 2);
}
Also used : InputSource(org.xml.sax.InputSource) ConfigSourceInfo(org.apache.sling.commons.log.logback.internal.ConfigSourceTracker.ConfigSourceInfo) SaxEventRecorder(ch.qos.logback.core.joran.event.SaxEventRecorder) JoranException(ch.qos.logback.core.joran.spi.JoranException) SaxEvent(ch.qos.logback.core.joran.event.SaxEvent) ArrayList(java.util.ArrayList)

Aggregations

SaxEvent (ch.qos.logback.core.joran.event.SaxEvent)3 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 SaxEventRecorder (ch.qos.logback.core.joran.event.SaxEventRecorder)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 OnConsoleStatusListener (ch.qos.logback.core.status.OnConsoleStatusListener)1 StatusListener (ch.qos.logback.core.status.StatusListener)1 StatusListenerAsList (ch.qos.logback.core.status.StatusListenerAsList)1 StatusUtil (ch.qos.logback.core.status.StatusUtil)1 ArrayList (java.util.ArrayList)1 ConfigSourceInfo (org.apache.sling.commons.log.logback.internal.ConfigSourceTracker.ConfigSourceInfo)1 InputSource (org.xml.sax.InputSource)1