Skip to content

Commit

Permalink
print error if logging fails
Browse files Browse the repository at this point in the history
  • Loading branch information
hrfee committed Dec 20, 2021
1 parent ebb49fc commit d81679f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions log.go
Expand Up @@ -14,14 +14,15 @@ import (
var logPath string = filepath.Join(temp, "jfa-go.log")
var lineCache = linecache.NewLineCache(100)

func logOutput() (closeFunc func()) {
func logOutput() (closeFunc func(), err error) {
old := os.Stdout
writers := []io.Writer{old, colorStripper{lineCache}}
wExit := make(chan bool)
r, w, _ := os.Pipe()
var f *os.File
if TRAY {
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 {
closeFunc = func() {}
return
Expand Down
5 changes: 4 additions & 1 deletion main.go
Expand Up @@ -667,7 +667,10 @@ func printVersion() {
}

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

0 comments on commit d81679f

Please sign in to comment.