Skip to content
Snippets Groups Projects
Verified Commit d34d6257 authored by meskio's avatar meskio :tent:
Browse files

[feat] add logger file

- Resolves: #56
parent ce244d75
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,10 @@ package main ...@@ -18,8 +18,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"path"
"runtime" "runtime"
"0xacab.org/leap/bitmask-systray/bitmask" "0xacab.org/leap/bitmask-systray/bitmask"
...@@ -40,6 +42,13 @@ func main() { ...@@ -40,6 +42,13 @@ func main() {
// locking the main thread into an OS thread fixes the problem // locking the main thread into an OS thread fixes the problem
runtime.LockOSThread() runtime.LockOSThread()
logger, err := configureLogger()
if err != nil {
log.Println("Can't configure logger: %v", err)
} else {
defer logger.Close()
}
conf := parseConfig() conf := parseConfig()
initPrinter() initPrinter()
...@@ -55,7 +64,7 @@ func main() { ...@@ -55,7 +64,7 @@ func main() {
os.MkdirAll(bitmask.ConfigPath, os.ModePerm) os.MkdirAll(bitmask.ConfigPath, os.ModePerm)
} }
err := acquirePID() err = acquirePID()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
...@@ -117,6 +126,14 @@ func maybeStartVPN(b bitmask.Bitmask, conf *systrayConfig) error { ...@@ -117,6 +126,14 @@ func maybeStartVPN(b bitmask.Bitmask, conf *systrayConfig) error {
return err 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() { func initPrinter() {
locale, err := go_locale.DetectLocale() locale, err := go_locale.DetectLocale()
if err != nil { if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment