diff --git a/cmd/minikube/cmd/logs.go b/cmd/minikube/cmd/logs.go index a1bfc5984b55..7924ba7c24fb 100644 --- a/cmd/minikube/cmd/logs.go +++ b/cmd/minikube/cmd/logs.go @@ -97,5 +97,5 @@ var logsCmd = &cobra.Command{ func init() { logsCmd.Flags().BoolVarP(&followLogs, "follow", "f", false, "Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.") logsCmd.Flags().BoolVar(&showProblems, "problems", false, "Show only log entries which point to known problems") - logsCmd.Flags().IntVarP(&numberOfLines, "length", "n", 50, "Number of lines back to go within the log") + logsCmd.Flags().IntVarP(&numberOfLines, "length", "n", 30, "Number of lines back to go within the log") } diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 0d88ef1c2863..88ed475be12b 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -136,3 +136,8 @@ func (r *Containerd) StopContainers(ids []string) error { func (r *Containerd) ContainerLogCmd(id string, len int, follow bool) string { return criContainerLogCmd(id, len, follow) } + +// SystemLogCmd returns the command to retrieve system logs +func (r *Containerd) SystemLogCmd(len int) string { + return fmt.Sprintf("sudo journalctl -u containerd -n %d", len) +} diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 03711280a817..4c9a8bb1929e 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -133,3 +133,8 @@ func (r *CRIO) StopContainers(ids []string) error { func (r *CRIO) ContainerLogCmd(id string, len int, follow bool) string { return criContainerLogCmd(id, len, follow) } + +// SystemLogCmd returns the command to retrieve system logs +func (r *CRIO) SystemLogCmd(len int) string { + return fmt.Sprintf("sudo journalctl -u crio -n %d", len) +} diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index 645c15c0b4f2..b7b74e131094 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -66,6 +66,8 @@ type Manager interface { StopContainers([]string) error // ContainerLogCmd returns the command to retrieve the log for a container based on ID ContainerLogCmd(string, int, bool) string + // SystemLogCmd returns the command to return the system logs + SystemLogCmd(int) string } // Config is runtime configuration diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index 709d8e67b5f5..817049aff132 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -153,3 +153,8 @@ func (r *Docker) ContainerLogCmd(id string, len int, follow bool) string { cmd.WriteString(id) return cmd.String() } + +// SystemLogCmd returns the command to retrieve system logs +func (r *Docker) SystemLogCmd(len int) string { + return fmt.Sprintf("sudo journalctl -u docker -n %d", len) +} diff --git a/pkg/minikube/logs/logs.go b/pkg/minikube/logs/logs.go index cc6d67a4116b..8107047aa7da 100644 --- a/pkg/minikube/logs/logs.go +++ b/pkg/minikube/logs/logs.go @@ -113,16 +113,14 @@ func OutputProblems(problems map[string][]string, maxLines int) { // Output displays logs from multiple sources in tail(1) format func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Runner, lines int) error { cmds := logCommands(r, bs, lines, false) - - // These are not technically logs, but are useful to have in bug reports. cmds["kernel"] = "uptime && uname -a && grep PRETTY /etc/os-release" names := []string{} for k := range cmds { names = append(names, k) } - sort.Strings(names) + sort.Strings(names) failed := []string{} for i, name := range names { if i > 0 { @@ -130,6 +128,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run } out.T(out.Empty, "==> {{.name}} <==", out.V{"name": name}) var b bytes.Buffer + err := runner.CombinedOutputTo(cmds[name], &b) if err != nil { glog.Errorf("failed: %v", err) @@ -141,6 +140,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run out.T(out.Empty, scanner.Text()) } } + if len(failed) > 0 { return fmt.Errorf("unable to fetch logs for: %s", strings.Join(failed, ", ")) } @@ -163,5 +163,8 @@ func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, length int, f } cmds[pod] = r.ContainerLogCmd(ids[0], length, follow) } + cmds[r.Name()] = r.SystemLogCmd(length) + // Works across container runtimes with good formatting + cmds["container status"] = "sudo crictl ps -a" return cmds }