forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathlog_config_delimiter.go
95 lines (85 loc) · 2.45 KB
/
log_config_delimiter.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"github.com/aliyun/aliyun-log-go-sdk"
config "github.com/aliyun/aliyun-log-go-sdk/example/config/util"
"github.com/aliyun/aliyun-log-go-sdk/example/util"
)
func main() {
// log config sample
testConf := "test-conf"
exist, err := config.CheckConfigExist(testConf)
fmt.Println(exist)
if err != nil {
fmt.Println("check conf exist fail:", err)
return
}
if exist {
config.DeleteConfig(testConf)
}
err = createDelimiterConfig(testConf, util.ProjectName, util.LogStoreName)
if err != nil {
fmt.Println("create config fail:", err)
return
}
fmt.Println("create common regex logtail config sucessed")
updateDelimiterConfig(testConf)
config.GetConfig(testConf)
exist, err = config.CheckConfigExist(testConf)
if err != nil {
fmt.Println(err)
return
}
if !exist {
fmt.Println("config:" + testConf + " should be exist")
return
}
config.DeleteConfig(testConf)
fmt.Println("delete common regex logtail config sucessed")
exist, err = config.CheckConfigExist(testConf)
if err != nil {
return
}
if exist {
fmt.Println("config:" + testConf + " should not be exist")
return
}
fmt.Println("log config sample end")
}
func createDelimiterConfig(configName string, projectName string, logstore string) (err error) {
delimiterConfig := new(sls.DelimiterConfigInputDetail)
sls.InitDelimiterConfigInputDetail(delimiterConfig)
delimiterConfig.Quote = "\u0001"
delimiterConfig.Key = []string{"1", "2", "3", "4", "5"}
delimiterConfig.Separator = "\""
// TimeKey and TimeFormat are optional, use system time as log time if not configed
delimiterConfig.TimeKey = "1"
delimiterConfig.TimeFormat = "xxxx"
delimiterConfig.LogPath = "/var/log/log"
delimiterConfig.FilePattern = "xxxx.log"
outputDetail := sls.OutputDetail{
ProjectName: projectName,
LogStoreName: logstore,
}
logConfig := &sls.LogConfig{
Name: configName,
InputType: "file",
OutputType: "LogService", // Now only supports LogService
InputDetail: delimiterConfig,
OutputDetail: outputDetail,
}
err = util.Client.CreateConfig(projectName, logConfig)
if err != nil {
return err
}
return nil
}
func updateDelimiterConfig(configName string) {
logtailConfig, _ := util.Client.GetConfig(util.ProjectName, configName)
inputDetail, _ := sls.ConvertToDelimiterConfigInputDetail(logtailConfig.InputDetail)
inputDetail.FilePattern = "*.log"
err := util.Client.UpdateConfig(util.ProjectName, logtailConfig)
if err != nil {
panic(err)
}
}