-
Notifications
You must be signed in to change notification settings - Fork 186
/
files.go
54 lines (47 loc) · 1.37 KB
/
files.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package logs
import (
"github.com/aws/amazon-cloudwatch-agent/tool/runtime"
)
type Files struct {
FileConfigs []*Config
}
func (config *Files) ToMap(ctx *runtime.Context) (string, map[string]interface{}) {
resultMap := make(map[string]interface{})
collectList := []map[string]interface{}{}
for i := range config.FileConfigs {
_, singleFile := config.FileConfigs[i].ToMap(ctx)
collectList = append(collectList, singleFile)
}
resultMap["collect_list"] = collectList
return "files", resultMap
}
func (config *Files) AddLogFile(filePath, logGroupName, logStreamName string, timestampFormat, timezone, multiLineStartPattern, encoding string, retention int) {
if config.FileConfigs == nil {
config.FileConfigs = []*Config{}
}
singleFile := &Config{
FilePath: filePath,
LogGroup: logGroupName,
}
if timestampFormat != "" {
singleFile.TimestampFormat = timestampFormat
}
if timezone != "" {
singleFile.Timezone = timezone
}
if multiLineStartPattern != "" {
singleFile.MultiLineStartPattern = multiLineStartPattern
}
if logStreamName != "" {
singleFile.LogStream = logStreamName
}
if encoding != "" {
singleFile.Encoding = encoding
}
if retention != 0 {
singleFile.Retention = retention
}
config.FileConfigs = append(config.FileConfigs, singleFile)
}