dynamo-browse/internal/common/ui/logging/debug.go
Leon Mika 41af399215 A few various changes
- Fixed the '-local' flag to accept host and port
- Added a '-debug' flag to accept a file to write debug log messages
- Added some logic which will force the dark background flag on if MacOS is in dark mode
2022-06-16 22:00:25 +10:00

29 lines
464 B
Go

package logging
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"os"
)
func EnableLogging(logFile string) (closeFn func()) {
if logFile == "" {
tempFile, err := os.CreateTemp("", "debug.log")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
tempFile.Close()
logFile = tempFile.Name()
}
f, err := tea.LogToFile(logFile, "debug")
if err != nil {
fmt.Println("fatal:", err)
os.Exit(1)
}
return func() {
f.Close()
}
}