package logs

import (
	log "app.yhyue.com/moapp/jylog"
	"bp.jydev.jianyu360.cn/BaseService/gateway/common/db"
	"bp.jydev.jianyu360.cn/BaseService/gateway/core/logs/internal/notice"
	"bp.jydev.jianyu360.cn/BaseService/gateway/core/logs/internal/savedb"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
)

var GateWayServerLog *serverLog

func InitLogs() {
	//初始化通知
	var noticeConfig notice.NoticeConfig
	ctx := gctx.New()
	if err := g.Cfg().MustGet(ctx, "alarm").Scan(&noticeConfig); err != nil {
		log.WithContext(ctx).Errorf("nsq通知配置异常 %v", err)
	}

	noticeObj, err := notice.NewNotice(noticeConfig)
	if err != nil {
		log.WithContext(ctx).Errorf("nsq通知初始化异常异常 %v", err)
	}

	// 持久化化存储
	sDB := &savedb.DbLogs{}

	sDB = new(savedb.DbLogs)
	sDB.Db = db.MgoLog

	GateWayServerLog = new(serverLog)

	if noticeObj != nil {
		GateWayServerLog.initNotice(noticeObj)
	}

	if sDB != nil {
		GateWayServerLog.initSaveLog(sDB)
	}
}
