package com.yida.data.system.configure;

import com.yida.data.system.collect.RedisLogCollect;
import com.yida.data.system.service.LogService;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import cc.mrbird.febs.common.redis.service.RedisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 日志收集启动类
 *
 * @author ZYJ
 * @date 2021/1/18
 */
@Component
@Order(100)
@Slf4j
@RequiredArgsConstructor
public class CollectLogStartBean implements InitializingBean {

    private final RedisService redisService;

    private final LogService logService;

    /**
     * 配置启动后拉取日志数据
     *
     * @author ZYJ
     * @date 2021/1/18 9:23
     */
    @Override
    public void afterPropertiesSet() {
        try {
            //调用拉取日志方法
            logServerStart();
        } catch (Exception e) {
            log.error("启动日志收集服务失败: {}", e.getMessage(), e);
        }
    }

    /**
     * 启动redis拉取数据类
     *
     * @author ZYJ
     * @date 2021/1/18 10:21
     */
    private void logServerStart() {
        RedisLogCollect redisLogCollect = new RedisLogCollect(redisService, logService);
        redisLogCollect.redisServerStart();
    }
}
