From 443b3a0765d3439e5c61310f10a96a5b828e646a Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Wed, 18 May 2022 08:50:11 -0400 Subject: [PATCH 1/2] FIX #10 Implement logging --- .gitignore | 3 +++ main.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/.gitignore b/.gitignore index 3ce343b..5d9c8da 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ breakfast # Go workspace file go.work + +# Logs +logs/ diff --git a/main.go b/main.go index 50ccd60..86f006c 100644 --- a/main.go +++ b/main.go @@ -189,6 +189,15 @@ func (m model) View() string { } func main() { + // Logging example from the Bubbletea "simple" example. For some + // reason there's no file variable, and hence no file to `.Close()`. + logfilePath := os.Getenv("BUBBLETEA_LOG") + if logfilePath != "" { + if _, err := tea.LogToFile(logfilePath, "DEBUG"); err != nil { + log.Fatal(err) + } + } + p := tea.NewProgram(initialModel()) if err := p.Start(); err != nil { fmt.Printf("Alas, there's been an error: %v", err) From d020c708cb166490ec74c84b5bebcd61722ff0a1 Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Wed, 18 May 2022 08:52:53 -0400 Subject: [PATCH 2/2] Remove INFO log tags now that log prefix is implemented --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 86f006c..c0b3c8d 100644 --- a/main.go +++ b/main.go @@ -43,9 +43,9 @@ func getBrowserSessions() []commandChoice { log.Printf("Error finding user configuration directory: %v", err) return []commandChoice{} } - log.Printf("INFO userConfigDir: %+v", userConfigDir) + log.Printf("userConfigDir: %+v", userConfigDir) fileSystem := os.DirFS(userConfigDir) - log.Printf("INFO fileSystem: %+v", fileSystem) + log.Printf("fileSystem: %+v", fileSystem) fileList, err := fs.ReadDir(fileSystem, "local/share/qutebrowser/sessions") if err != nil { log.Printf("Error reading browser sessions directory: %v", err) @@ -56,7 +56,7 @@ func getBrowserSessions() []commandChoice { result := make([]commandChoice, 0) for _, entry := range fileList { if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".yml") { - log.Printf("INFO %s", entry.Name()) + log.Printf("%s", entry.Name()) result = append(result, commandChoice{ displayString: fmt.Sprintf("Qutebrowser session: %s", strings.TrimSuffix(entry.Name(), ".yml")), command: exec.Command("xterm", "-e", "qutebrowser", "--target", "window", "--restore", strings.TrimSuffix(entry.Name(), ".yml")), @@ -102,7 +102,7 @@ func launch(m model) tea.Cmd { var result statusMsg for q, item := range m.choices { if _, ok := m.selected[q]; ok { - log.Printf("INFO launching: %v\n", item.displayString) + log.Printf("launching: %v\n", item.displayString) result += statusMsg(fmt.Sprintf("Launching command: %v\n", item.displayString)) err := item.command.Start() if err != nil {