Utility function for logging to the system log

This commit is contained in:
Christian Rocha 2020-01-17 16:38:25 -05:00
parent 4f42c502ed
commit 051a370769
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 15 additions and 0 deletions

15
tea.go
View File

@ -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
}