改进 日志格式
This commit is contained in:
parent
0e37888c30
commit
56d9f01640
10
main.go
10
main.go
@ -88,8 +88,8 @@ func ValidatePassword(pass string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Process(logStruct LogStruct) error {
|
func Process(logStruct LogStruct) error {
|
||||||
fileName := GetPath(true, logStruct.Time.Year(), logStruct.Time.Month(), logStruct.Time.Day(), logStruct.Time.Hour(), logStruct.Kubernetes.NamespaceName, logStruct.Stream, logStruct.Kubernetes.ContainerName)
|
fileName := GetPath(true, logStruct.Time.Year(), logStruct.Time.Month(), logStruct.Time.Day(), logStruct.Kubernetes.NamespaceName, logStruct.Stream, logStruct.Kubernetes.ContainerName)
|
||||||
path := GetPath(false, logStruct.Time.Year(), logStruct.Time.Month(), logStruct.Time.Day(), logStruct.Time.Hour(), logStruct.Kubernetes.NamespaceName, logStruct.Stream, logStruct.Kubernetes.ContainerName)
|
path := GetPath(false, logStruct.Time.Year(), logStruct.Time.Month(), logStruct.Time.Day(), logStruct.Kubernetes.NamespaceName, logStruct.Stream, logStruct.Kubernetes.ContainerName)
|
||||||
|
|
||||||
// validate path exists
|
// validate path exists
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
@ -121,14 +121,14 @@ func Process(logStruct LogStruct) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPath(includeFileName bool, year int, month time.Month, day int, hour int, namespace string, stream string, containerName string) string {
|
func GetPath(includeFileName bool, year int, month time.Month, day int, namespace string, stream string, containerName string) string {
|
||||||
// dir + year/month/day/namespace/hour/podName-stream.log
|
// dir + year/month/day/namespace/hour/podName-stream.log
|
||||||
// month to int
|
// month to int
|
||||||
|
|
||||||
monthNumber := int(month)
|
monthNumber := int(month)
|
||||||
if includeFileName {
|
if includeFileName {
|
||||||
return fmt.Sprintf("%s/%d-%d/%d/%s/%d/%s-%s.log", config.Dir.Dir, year, monthNumber, day, namespace, hour, containerName, stream)
|
return fmt.Sprintf("%s/%s/%d-%d/%d/%s-%s.log", config.Dir.Dir, namespace, year, monthNumber, day, containerName, stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s/%d-%d/%d/%s/%d/", config.Dir.Dir, year, monthNumber, day, namespace, hour)
|
return fmt.Sprintf("%s/%s/%d-%d/%d/", config.Dir.Dir, namespace, year, monthNumber, day)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user