MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / ListSystemLogFile

Method ListSystemLogFile

agent/app/service/logs.go:22–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22func (u *LogService) ListSystemLogFile() ([]string, error) {
23 var listFile []string
24 files, err := os.ReadDir(global.Dir.LogDir)
25 if err != nil {
26 return nil, err
27 }
28 listMap := make(map[string]struct{})
29 for _, item := range files {
30 if item.IsDir() || !strings.HasPrefix(item.Name(), "1Panel") {
31 continue
32 }
33 if item.Name() == "1Panel.log" || item.Name() == "1Panel-Core.log" {
34 itemName := time.Now().Format("2006-01-02")
35 if _, ok := listMap[itemName]; ok {
36 continue
37 }
38 listMap[itemName] = struct{}{}
39 listFile = append(listFile, itemName)
40 continue
41 }
42 itemFileName := strings.TrimPrefix(item.Name(), "1Panel-Core-")
43 itemFileName = strings.TrimPrefix(itemFileName, "1Panel-")
44 itemFileName = strings.TrimSuffix(itemFileName, ".gz")
45 itemFileName = strings.TrimSuffix(itemFileName, ".log")
46 if len(itemFileName) == 0 {
47 continue
48 }
49 if _, ok := listMap[itemFileName]; ok {
50 continue
51 }
52 listMap[itemFileName] = struct{}{}
53 listFile = append(listFile, itemFileName)
54 }
55 if len(listFile) < 2 {
56 return listFile, nil
57 }
58 sort.Slice(listFile, func(i, j int) bool {
59 return listFile[i] > listFile[j]
60 })
61
62 return listFile, nil
63}

Callers

nothing calls this directly

Calls 4

ReadDirMethod · 0.80
IsDirMethod · 0.80
NameMethod · 0.65
FormatMethod · 0.45

Tested by

no test coverage detected