All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.qos.logback.classic.model.processor.ContextNameModelHandler Maven / Gradle / Ivy

There is a newer version: 1.3.5
Show newest version
package ch.qos.logback.classic.model.processor;

import ch.qos.logback.classic.model.ContextNameModel;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.processor.ModelHandlerBase;
import ch.qos.logback.core.model.processor.ModelHandlerException;

public class ContextNameModelHandler extends ModelHandlerBase {

	public ContextNameModelHandler(Context context) {
		super(context);
	}

	@Override
	protected Class getSupportedModelClass() {
		return ContextNameModel.class;
	}

	@Override
	public void handle(InterpretationContext intercon, Model model) throws ModelHandlerException {
		ContextNameModel contextNameModel = (ContextNameModel) model;

		String finalBody = intercon.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);
        }

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy