...
1
16
17 package services
18
19 import (
20 "encoding/json"
21 "flag"
22 "fmt"
23 )
24
25
26
27 type LogFileData struct {
28
29 Name string `json:"name"`
30
31 Files []string `json:"files"`
32
33 JournalctlCommand []string `json:"journalctl"`
34 }
35
36
37
38 type logFiles map[string]LogFileData
39
40
41 func (l *logFiles) String() string {
42 return fmt.Sprint(*l)
43 }
44
45
46 func (l *logFiles) Set(value string) error {
47 var log LogFileData
48 if err := json.Unmarshal([]byte(value), &log); err != nil {
49 return err
50 }
51
52 logs := *l
53 logs[log.Name] = log
54 return nil
55 }
56
57
58 var extraLogs = make(logFiles)
59
60 func init() {
61 flag.Var(&extraLogs, "extra-log", "Extra log to collect after test in the json format of LogFile.")
62 }
63
64
65 var requiredLogs = []LogFileData{
66 {
67 Name: "kern.log",
68 Files: []string{"/var/log/kern.log"},
69 JournalctlCommand: []string{"-k"},
70 },
71 {
72 Name: "cloud-init.log",
73 Files: []string{"/var/log/cloud-init.log", "/var/log/cloud-init-output.log"},
74 JournalctlCommand: []string{"-u", "cloud*"},
75 },
76 {
77 Name: "containerd.log",
78 Files: []string{"/var/log/containerd.log"},
79 JournalctlCommand: []string{"-u", "containerd"},
80 },
81 {
82 Name: "containerd-installation.log",
83 JournalctlCommand: []string{"-u", "containerd-installation"},
84 },
85 }
86
87
88 func getLogFiles() logFiles {
89 logs := make(logFiles)
90 for _, l := range requiredLogs {
91 logs[l.Name] = l
92 }
93 for _, l := range extraLogs {
94 logs[l.Name] = l
95 }
96 return logs
97 }
98
View as plain text