From 443b3a0765d3439e5c61310f10a96a5b828e646a Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Wed, 18 May 2022 08:50:11 -0400 Subject: [PATCH] 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)