syslog is only available on unix systems

This commit is contained in:
Christian Muehlhaeuser 2020-01-25 07:15:56 +01:00
parent bc67e3896b
commit 1c98700015
No known key found for this signature in database
GPG Key ID: 3CF9FA45CA1EBB7E
2 changed files with 23 additions and 16 deletions

22
logging.go Normal file
View File

@ -0,0 +1,22 @@
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package tea
import (
"log"
"log/syslog"
)
// UseSysLog sets up logging to log 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
}

17
tea.go
View File

@ -3,8 +3,7 @@ package tea
import (
"errors"
"io"
"log"
"log/syslog"
"os"
"strings"
)
@ -176,17 +175,3 @@ func (p *Program) render(model Model, linesRendered int) int {
io.WriteString(os.Stdout, view)
return strings.Count(view, "\r\n")
}
// UseSysLog sets up logging to log 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
}