Search in sources :

Example 1 with BodyEvent

use of ch.qos.logback.core.joran.event.BodyEvent in project quarkus-logging-logback by quarkiverse.

the class LogbackRecorder method init.

public void init(List<SaxEvent> originalEvents, Set<String> delayedStartClasses, ShutdownContext context, Map<String, String> buildSystemProps) {
    EventSubstitution substitution = new EventSubstitution();
    if (defaultLoggerContext == null) {
        SmallRyeConfig config = (SmallRyeConfig) SmallRyeConfigProviderResolver.instance().getConfig();
        List<SaxEvent> configEvents = new ArrayList<>();
        for (SaxEvent i : originalEvents) {
            if (i instanceof StartEvent) {
                AttributesImpl impl = (AttributesImpl) ((StartEvent) i).attributes;
                int index = impl.getIndex("class");
                if (index > -1) {
                    String val = impl.getValue(index);
                    if (delayedStartClasses.contains(val)) {
                        impl.setValue(index, val + DELAYED);
                    }
                }
                for (int j = 1; j <= impl.getLength(); ++j) {
                    String val = impl.getValue(index);
                    if (val != null && val.contains("${")) {
                        final String expanded = doExpand(config, val, buildSystemProps);
                        impl.setValue(j, expanded);
                    }
                }
                configEvents.add(i);
            } else if (i instanceof BodyEvent) {
                String val = ((BodyEvent) i).getText();
                if (val.contains("${")) {
                    final String expanded = doExpand(config, val, buildSystemProps);
                    configEvents.add(substitution.deserialize(new BodySub(i.getNamespaceURI(), i.getLocalName(), i.getQName(), i.getLocator(), expanded)));
                } else {
                    configEvents.add(i);
                }
            } else {
                configEvents.add(i);
            }
        }
        defaultLoggerContext = new LoggerContext();
        try {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(defaultLoggerContext);
            configurator.doConfigure(configEvents);
            // logback-292
            if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
                StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
            }
        } catch (Exception t) {
            // see LOGBACK-1159
            Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
        }
        context.addLastShutdownTask(new Runnable() {

            @Override
            public void run() {
                defaultLoggerContext.stop();
                defaultLoggerContext = null;
                started = false;
            }
        });
    }
}
Also used : BodySub(io.quarkiverse.logback.runtime.events.BodySub) ArrayList(java.util.ArrayList) BodyEvent(ch.qos.logback.core.joran.event.BodyEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) AttributesImpl(org.xml.sax.helpers.AttributesImpl) SmallRyeConfig(io.smallrye.config.SmallRyeConfig) SaxEvent(ch.qos.logback.core.joran.event.SaxEvent) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) StartEvent(ch.qos.logback.core.joran.event.StartEvent) EventSubstitution(io.quarkiverse.logback.runtime.events.EventSubstitution)

Example 2 with BodyEvent

use of ch.qos.logback.core.joran.event.BodyEvent in project logback-android by tony19.

the class EventPlayer method play.

public void play(List<SaxEvent> aSaxEventList) {
    eventList = aSaxEventList;
    SaxEvent se;
    for (currentIndex = 0; currentIndex < eventList.size(); currentIndex++) {
        se = eventList.get(currentIndex);
        if (se instanceof StartEvent) {
            interpreter.startElement((StartEvent) se);
            // invoke fireInPlay after startElement processing
            interpreter.getInterpretationContext().fireInPlay(se);
        }
        if (se instanceof BodyEvent) {
            // invoke fireInPlay before  characters processing
            interpreter.getInterpretationContext().fireInPlay(se);
            interpreter.characters((BodyEvent) se);
        }
        if (se instanceof EndEvent) {
            // invoke fireInPlay before endElement processing
            interpreter.getInterpretationContext().fireInPlay(se);
            interpreter.endElement((EndEvent) se);
        }
    }
}
Also used : SaxEvent(ch.qos.logback.core.joran.event.SaxEvent) StartEvent(ch.qos.logback.core.joran.event.StartEvent) EndEvent(ch.qos.logback.core.joran.event.EndEvent) BodyEvent(ch.qos.logback.core.joran.event.BodyEvent)

Aggregations

BodyEvent (ch.qos.logback.core.joran.event.BodyEvent)2 SaxEvent (ch.qos.logback.core.joran.event.SaxEvent)2 StartEvent (ch.qos.logback.core.joran.event.StartEvent)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 EndEvent (ch.qos.logback.core.joran.event.EndEvent)1 BodySub (io.quarkiverse.logback.runtime.events.BodySub)1 EventSubstitution (io.quarkiverse.logback.runtime.events.EventSubstitution)1 SmallRyeConfig (io.smallrye.config.SmallRyeConfig)1 ArrayList (java.util.ArrayList)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1