-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
60 lines (51 loc) · 1.38 KB
/
main.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
package main
import (
"context"
"flag"
"github.com/zeromicro/go-zero/core/logc"
"os"
"watchlog/log"
)
func main() {
// Command-line flags
template := flag.String("template", "", "Template filepath for fluentd or filebeat.")
flag.Parse()
// Set default Docker API version if not set
if err := setDefaultDockerAPIVersion(); err != nil {
logc.Errorf(context.Background(), err.Error())
return
}
// Validate runtime type
if os.Getenv("RUNTIME_TYPE") == "" {
panic("Please set service type, (docker|containerd)")
}
// Validate template
if *template == "" {
panic("template file cannot be empty")
}
// Run log processing
if err := log.Run(*template, getLogPrefix(), getBaseDir()); err != nil {
logc.Errorf(context.Background(), err.Error())
}
}
// setDefaultDockerAPIVersion sets the default Docker API version if not already set.
func setDefaultDockerAPIVersion() error {
if os.Getenv("DOCKER_API_VERSION") == "" {
return os.Setenv("DOCKER_API_VERSION", "1.24")
}
return nil
}
// getLogPrefix retrieves the log prefix from the environment or defaults to "watchlog".
func getLogPrefix() string {
if lp := os.Getenv("LOG_PREFIX"); len(lp) > 0 {
return lp
}
return "watchlog"
}
// getBaseDir get log base store dir or defaults to "/host/var/log/pods"
func getBaseDir() string {
if lbd := os.Getenv("LOG_BASE_DIR"); len(lbd) > 0 {
return lbd
}
return "/host/var/log/pods"
}