package org.nl.config.lucene;

import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.pattern.PatternLayoutBase;

/*
 * @author ZZQ
 * @Date 2023/12/22 18:11
 */
public class LucenePropertyAndEncoder {

    private Property property;

    private  PatternLayoutBase layout = new PatternLayout();

    public LucenePropertyAndEncoder(Property property, Context context) {
        this.property = property;
        this.layout.setContext(context);
        this.layout.setPattern(String.valueOf(property.getValue()));
        this.layout.setPostCompileProcessor(null);
        this.layout.start();
    }

    public String encode(ILoggingEvent event) {
        return layout.doLayout(event);
    }

    public String getName() {
        return property.getName();
    }

    public boolean allowEmpty() {
        return property.isAllowEmpty();
    }
}

