use of io.quarkiverse.logback.runtime.events.EventSubstitution 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;
}
});
}
}
Aggregations