package cn.reghao.autodop.dmaster.util.log;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
import cn.reghao.autodop.dmaster.machine.db.crud.NodeLogCrud;
import org.slf4j.LoggerFactory;

/**
 * @author reghao
 * @date 2021-06-11 13:31:20
 */
public class Appenders {
    private static final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    
    public static Appender<ILoggingEvent> mongoAppender(NodeLogCrud nodeLogCrud) {
        PatternLayoutEncoder layoutEncoder = new PatternLayoutEncoder();
        layoutEncoder.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
        layoutEncoder.setContext(loggerContext);
        layoutEncoder.start();

        MongoAppender mongoAppender = new MongoAppender(nodeLogCrud);
        mongoAppender.setContext(loggerContext);
        mongoAppender.start();
        return mongoAppender;
    }
}
