| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package model
- import (
- "bytes"
- "context"
- "rocommon/service"
- "rocommon/util"
- "runtime"
- "strconv"
- "time"
- )
- type ElasticLogST struct {
- Uid uint64 `json:"uid"` //用户唯一ID
- NickName string `json:"nickname"`
- LogTime time.Time `json:"logtime"`
- OpenId string `json:"openid"`
- LogType string `json:"logtype"` //日志类型,例如是登录日志,消费日志等
- LogDesc string `json:"logdesc"` //描述
- LogLine string `json:"logline"` //代码行信息
- NodeZone int `json:"nodezone"` //服务器节点信息
- NodeId int `json:"nodeid"`
- NodeType int `json:"nodetype"`
- Param1 int `json:"param1"`
- }
- /*
- LogType:
- RoleRegister
- RoleOnline
- RoleOnlineNum
- RoleOffline
- */
- //ro index 数据,后续可以添加其他索引模式的log数据
- func ElasticPutLogInfo(logInfo *ElasticLogST) {
- if service.GetElastic() != nil {
- //ServerNodeInfo
- logInfo.NodeZone = service.GetServiceConfig().Node.Zone
- logInfo.NodeId = service.GetServiceConfig().Node.Id
- logInfo.NodeType = service.GetServiceConfig().Node.Type
- logInfo.LogTime = util.GetCurrentTimeNow()
- _, file, line, ok := runtime.Caller(1)
- if !ok {
- file = "???"
- line = 0
- }
- strBuf := bytes.NewBufferString(file)
- strBuf.WriteString(":")
- strBuf.WriteString(strconv.Itoa(line))
- logInfo.LogLine = strBuf.String()
- ctx := context.Background()
- go func() {
- _, err := service.GetElastic().Index().Index("ro").BodyJson(logInfo).Do(ctx)
- if err != nil {
- util.InfoF("ElasticPutLogInfo uuid=%v err=%v", logInfo.Uid, err)
- return
- }
- //util.InfoF("ElasticPutLogInfo logtype= uuid=%v ok line=%v", logInfo.LogType, logInfo.Uid, logInfo.LogLine)
- }()
- } else {
- //util.InfoF("ElasticPutLogInfo uuid=%v elastic is nil", logInfo.Uid)
- }
- }
|