org.apache.juli.logging.ch.qos.logback.classic.model.processor.ContextNameModelHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tomcat85-slf4j-logback Show documentation
Show all versions of tomcat85-slf4j-logback Show documentation
Tomcat85 Slf4j Logback Integration
package org.apache.juli.logging.ch.qos.logback.classic.model.processor;
import org.apache.juli.logging.ch.qos.logback.classic.model.ContextNameModel;
import org.apache.juli.logging.ch.qos.logback.core.Context;
import org.apache.juli.logging.ch.qos.logback.core.model.Model;
import org.apache.juli.logging.ch.qos.logback.core.model.processor.ModelHandlerBase;
import org.apache.juli.logging.ch.qos.logback.core.model.processor.ModelHandlerException;
import org.apache.juli.logging.ch.qos.logback.core.model.processor.ModelInterpretationContext;
public class ContextNameModelHandler extends ModelHandlerBase {
public ContextNameModelHandler(Context context) {
super(context);
}
static public ModelHandlerBase makeInstance(Context context, ModelInterpretationContext ic) {
return new ContextNameModelHandler(context);
}
@Override
protected Class getSupportedModelClass() {
return ContextNameModel.class;
}
@Override
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {
ContextNameModel contextNameModel = (ContextNameModel) model;
String finalBody = mic.subst(contextNameModel.getBodyText());
addInfo("Setting logger context name as [" + finalBody + "]");
try {
context.setName(finalBody);
} catch (IllegalStateException e) {
addError("Failed to rename context [" + context.getName() + "] as [" + finalBody + "]", e);
}
}
}