print error if logging fails

tailwind
Harvey Tindall 3 years ago
parent ebb49fce97
commit d81679fbae
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -14,14 +14,15 @@ import (
var logPath string = filepath.Join(temp, "jfa-go.log") var logPath string = filepath.Join(temp, "jfa-go.log")
var lineCache = linecache.NewLineCache(100) var lineCache = linecache.NewLineCache(100)
func logOutput() (closeFunc func()) { func logOutput() (closeFunc func(), err error) {
old := os.Stdout old := os.Stdout
writers := []io.Writer{old, colorStripper{lineCache}} writers := []io.Writer{old, colorStripper{lineCache}}
wExit := make(chan bool) wExit := make(chan bool)
r, w, _ := os.Pipe() r, w, _ := os.Pipe()
var f *os.File
if TRAY { if TRAY {
log.Printf("Logging to \"%s\"", logPath) log.Printf("Logging to \"%s\"", logPath)
f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) f, err = os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil { if err != nil {
closeFunc = func() {} closeFunc = func() {}
return return

@ -667,7 +667,10 @@ func printVersion() {
} }
func main() { func main() {
f := logOutput() f, err := logOutput()
if err != nil {
fmt.Printf("Failed to start logging: %v\n", err)
}
defer f() defer f()
printVersion() printVersion()
SOCK = filepath.Join(temp, SOCK) SOCK = filepath.Join(temp, SOCK)

Loading…
Cancel
Save