summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-06-28 19:04:56 +0200
committerRuben Pollan <meskio@sindominio.net>2018-07-04 01:30:44 +0200
commitd34d6257d50608f32d73b5ea53b1efeab1072cd1 (patch)
tree945cd233ecc6996d0e4a385c2217428502730a0e
parentce244d757b68f27283336a60be33f10639ec6a3a (diff)
[feat] add logger file
- Resolves: #56
-rw-r--r--main.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/main.go b/main.go
index 56198bd..75745da 100644
--- a/main.go
+++ b/main.go
@@ -18,8 +18,10 @@ package main
import (
"flag"
"fmt"
+ "io"
"log"
"os"
+ "path"
"runtime"
"0xacab.org/leap/bitmask-systray/bitmask"
@@ -40,6 +42,13 @@ func main() {
// locking the main thread into an OS thread fixes the problem
runtime.LockOSThread()
+ logger, err := configureLogger()
+ if err != nil {
+ log.Println("Can't configure logger: %v", err)
+ } else {
+ defer logger.Close()
+ }
+
conf := parseConfig()
initPrinter()
@@ -55,7 +64,7 @@ func main() {
os.MkdirAll(bitmask.ConfigPath, os.ModePerm)
}
- err := acquirePID()
+ err = acquirePID()
if err != nil {
log.Fatal(err)
}
@@ -117,6 +126,14 @@ func maybeStartVPN(b bitmask.Bitmask, conf *systrayConfig) error {
return err
}
+func configureLogger() (io.Closer, error) {
+ logFile, err := os.OpenFile(path.Join(bitmask.ConfigPath, "systray.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+ if err == nil {
+ log.SetOutput(io.MultiWriter(logFile, os.Stderr))
+ }
+ return logFile, err
+}
+
func initPrinter() {
locale, err := go_locale.DetectLocale()
if err != nil {