Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5148627d2d | |||
| da1e982ab5 |
45
package/gamelog/export.go
Normal file
45
package/gamelog/export.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package gamelog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取日志行
|
||||||
|
func (sdk *SDK) GetLogItem(uid, event string, property map[string]any, timezone string, customEventTime ...time.Time) string {
|
||||||
|
loc := time.Local
|
||||||
|
if _loc := getLocationMapValue(timezone); _loc != nil {
|
||||||
|
loc = _loc
|
||||||
|
}
|
||||||
|
if len(property) == 0 {
|
||||||
|
property = map[string]any{"ts": gtime.Now().Timestamp()}
|
||||||
|
}
|
||||||
|
var et *gtime.Time
|
||||||
|
if len(customEventTime) > 0 {
|
||||||
|
et = gtime.NewFromTime(customEventTime[0])
|
||||||
|
} else {
|
||||||
|
et = gtime.Now()
|
||||||
|
}
|
||||||
|
pstr, err := json.Marshal(property)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal property err: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
item := []any{
|
||||||
|
uid,
|
||||||
|
event,
|
||||||
|
pstr,
|
||||||
|
et.TimestampMilli(),
|
||||||
|
et.In(loc).Format(datetimeFmt),
|
||||||
|
}
|
||||||
|
itemstr, err := json.Marshal(item)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal item err: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return gconv.String(itemstr)
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
type sendBody struct {
|
type sendBody struct {
|
||||||
Pid string `json:"pid"`
|
Pid string `json:"pid"`
|
||||||
Data [][]any `json:"data"`
|
Data [][]any `json:"data"`
|
||||||
|
SaveType int `json:"save_type" dc:"0=文件存储, 1=kafka存储"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 游戏日志对象
|
// todo 游戏日志对象
|
||||||
@@ -42,6 +43,7 @@ type SDKConfig struct {
|
|||||||
ChanSize int // 信道大小, 默认1000
|
ChanSize int // 信道大小, 默认1000
|
||||||
|
|
||||||
reportN int
|
reportN int
|
||||||
|
SendSaveType int // 发送存储类型, 默认不设置为0代表文件存储, 1代表走kafka可实同步日志
|
||||||
}
|
}
|
||||||
|
|
||||||
type SDK struct {
|
type SDK struct {
|
||||||
@@ -381,6 +383,7 @@ func (sdk *SDK) send(logs []GameLog) {
|
|||||||
sbody := sendBody{
|
sbody := sendBody{
|
||||||
Pid: sdk.sdkConfig.Pid,
|
Pid: sdk.sdkConfig.Pid,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
SaveType: sdk.sdkConfig.SendSaveType,
|
||||||
}
|
}
|
||||||
jsonBody, err := json.Marshal(sbody)
|
jsonBody, err := json.Marshal(sbody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ func TestGamelog(t *testing.T) {
|
|||||||
// 可填
|
// 可填
|
||||||
RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据
|
RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据
|
||||||
ChanSize: 500, // 默认1000, 信道size
|
ChanSize: 500, // 默认1000, 信道size
|
||||||
|
SendSaveType: 1, // 发送存储类型, 默认不设置为0代表文件存储, 1代表走kafka可实同步日志
|
||||||
})
|
})
|
||||||
|
|
||||||
// 随机测试事件和属性
|
// 随机测试事件和属性
|
||||||
|
|||||||
Reference in New Issue
Block a user