package cn.reghao.tnb.content.app.config;

import cn.reghao.tnb.common.log.LoggerConfig;
import cn.reghao.tnb.content.app.util.rabbit.RabbitAppender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author reghao
 * @date 2022-03-28 11:54:49
 */
@Slf4j
@Component
public class SpringLifecycle implements ApplicationRunner, DisposableBean {
    private final RabbitAppender rabbitAppender;

    public SpringLifecycle(RabbitAppender rabbitAppender) {
        this.rabbitAppender = rabbitAppender;
    }

    @Override
    public void run(ApplicationArguments args) {
        //initLogConfig(rabbitAppender);
        log.info("ContentService 启动...");
    }

    private void initLogConfig(RabbitAppender rabbitAppender) {
        log.info("ContentService use RabbitAppender...");
        LoggerConfig.initLogger(List.of(rabbitAppender));
    }

    @Override
    public void destroy() {
        log.info("ContentService 停止...");
    }
}
