From 051a37076915ba0ef3543215db26aed23faf6450 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 17 Jan 2020 16:38:25 -0500 Subject: [PATCH] Utility function for logging to the system log --- tea.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tea.go b/tea.go index 5af309b..53fc49e 100644 --- a/tea.go +++ b/tea.go @@ -3,6 +3,8 @@ package tea import ( "fmt" "io" + "log" + "log/syslog" "strings" "github.com/pkg/term" @@ -210,3 +212,16 @@ func ExitFullscreen() { func ClearScreen() { fmt.Printf(esc + "2J" + esc + "3J" + esc + "1;1H") } + +// UseSysLog logs to the system log. This becomes helpful when debugging since +// we can't easily print to the terminal since our TUI is occupying it! +// +// On macOS this is a just a matter of: tail -f /var/log/system.log +func UseSysLog(programName string) error { + l, err := syslog.New(syslog.LOG_NOTICE, programName) + if err != nil { + return err + } + log.SetOutput(l) + return nil +}