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

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

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

import static ch.qos.logback.core.joran.JoranConstants.INHERITED;
import static ch.qos.logback.core.joran.JoranConstants.NULL;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.model.LevelModel;
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 LevelModelHandler extends ModelHandlerBase {

	boolean inError = false;

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

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

	@Override
	public void handle(InterpretationContext intercon, Model model) throws ModelHandlerException {

		Object o = intercon.peekObject();

		if (!(o instanceof Logger)) {
			inError = true;
			addError("For element , could not find a logger at the top of execution stack.");
			return;
		}

		Logger l = (Logger) o;
	    String loggerName = l.getName();
	    
		LevelModel levelModel = (LevelModel) model;
		String levelStr = intercon.subst(levelModel.getValue());
		if (INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
			l.setLevel(null);
		} else {
			l.setLevel(Level.toLevel(levelStr, Level.DEBUG));
		}

		addInfo(loggerName + " level set to " + l.getLevel());

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy