add command line option for log file

cc #739
This commit is contained in:
Gokcehan committed 2022-02-06 19:51:52 +03:00
1 parent 5d393da572
commit 47620fa680
11 files changed
+38 -15

No files matched your search

+10 -5
View File
@@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
@@ -25,12 +26,16 @@ func run() {
screen.EnableMouse()
}
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
panic(err)
if gLogPath != "" {
f, err := os.OpenFile(gLogPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
panic(err)
}
defer f.Close()
log.SetOutput(f)
} else {
log.SetOutput(ioutil.Discard)
}
defer f.Close()
log.SetOutput(f)
log.Print("hi!")