forked from aliyun/aliyun-log-go-sdk
/
utils.go
46 lines (38 loc) · 924 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package producer
import (
"github.com/aliyun/aliyun-log-go-sdk"
"github.com/gogo/protobuf/proto"
)
func GenerateLog(logTime uint32, addLogMap map[string]string) *sls.Log {
content := []*sls.LogContent{}
for key, value := range addLogMap {
content = append(content, &sls.LogContent{
Key: proto.String(key),
Value: proto.String(value),
})
}
return &sls.Log{
Time: proto.Uint32(logTime),
Contents: content,
}
}
func GetTimeMs(t int64) int64 {
return t / 1000 / 1000
}
func GetLogSizeCalculate(log *sls.Log) int {
sizeInBytes := 4
logContent := log.GetContents()
count := len(logContent)
for i := 0; i < count; i++ {
sizeInBytes += len(*logContent[i].Value)
sizeInBytes += len(*logContent[i].Key)
}
return sizeInBytes
}
func GetLogListSize(logList []*sls.Log) int {
sizeInBytes := 0
for _, log := range logList {
sizeInBytes += GetLogSizeCalculate(log)
}
return sizeInBytes
}