package main

import (
	"fmt"
	"jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
	"jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mysqldb"
	"os"
	"timedtasks/config"
)

var (
	Es        *elastic.Elastic
	MysqlTool *mysqldb.Mysql
)

// InitLog @Description
// @Author J 2022/7/26 15:30
func InitLog() {
	logcfg := config.Conf.Log

	err := log.InitLog(
		log.Path(logcfg.LogPath),
		log.Level(logcfg.LogLevel),
		log.Compress(logcfg.Compress),
		log.MaxSize(logcfg.MaxSize),
		log.MaxBackups(logcfg.MaxBackups),
		log.MaxAge(logcfg.MaxAge),
		log.Format(logcfg.Format),
	)
	if err != nil {
		fmt.Printf("InitLog failed: %v\n", err)
		os.Exit(1)
	}
}

func InitMysql() {
	dbcfg := config.Conf.Mysql
	MysqlTool = &mysqldb.Mysql{
		Address:  dbcfg.Addr,
		DBName:   dbcfg.Dbname,
		UserName: dbcfg.User,
		PassWord: dbcfg.Password,
	}
	MysqlTool.Init()
}

func initEs() {
	escfg := config.Conf.Es

	Es = &elastic.Elastic{
		S_esurl:  escfg.Addr,
		I_size:   escfg.Size,
		Username: escfg.Username,
		Password: escfg.Password,
	}
	Es.InitElasticSize()
}
