summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-14 03:38:06 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-14 03:38:06 +0200
commitc1e097d6d0cabb81b3aa180d69107f9857606bf5 (patch)
tree000c3ba19fa2c3a6da7fe848cdaf9e9d313cede8
parente75d2d4496643ef6b4033d574cd47b92aeb21a11 (diff)
Optional logging even in background
-rw-r--r--logger.go8
-rw-r--r--main.go13
-rw-r--r--uapi.go1
3 files changed, 16 insertions, 6 deletions
diff --git a/logger.go b/logger.go
index b8012aa..849f674 100644
--- a/logger.go
+++ b/logger.go
@@ -13,7 +13,8 @@ import (
)
const (
- LogLevelError = iota
+ LogLevelSilent = iota
+ LogLevelError
LogLevelInfo
LogLevelDebug
)
@@ -35,7 +36,10 @@ func NewLogger(level int, prepend string) *Logger {
if level >= LogLevelInfo {
return output, output, ioutil.Discard
}
- return output, ioutil.Discard, ioutil.Discard
+ if level >= LogLevelError {
+ return output, ioutil.Discard, ioutil.Discard
+ }
+ return ioutil.Discard, ioutil.Discard, ioutil.Discard
}()
logger.Debug = log.New(logDebug,
diff --git a/main.go b/main.go
index 5001bc4..6c7b07d 100644
--- a/main.go
+++ b/main.go
@@ -111,6 +111,8 @@ func main() {
return LogLevelInfo
case "error":
return LogLevelError
+ case "silent":
+ return LogLevelSilent
}
return LogLevelInfo
}()
@@ -183,11 +185,16 @@ func main() {
env = append(env, fmt.Sprintf("%s=3", ENV_WG_TUN_FD))
env = append(env, fmt.Sprintf("%s=4", ENV_WG_UAPI_FD))
env = append(env, fmt.Sprintf("%s=1", ENV_WG_PROCESS_FOREGROUND))
+ files := [3]*os.File{}
+ if os.Getenv("LOG_LEVEL") != "" {
+ files[1] = os.Stdout
+ files[2] = os.Stderr
+ }
attr := &os.ProcAttr{
Files: []*os.File{
- nil, // stdin
- nil, // stdout
- nil, // stderr
+ files[0], // stdin
+ files[1], // stdout
+ files[2], // stderr
tun.File(),
fileUAPI,
},
diff --git a/uapi.go b/uapi.go
index 9858f60..f846033 100644
--- a/uapi.go
+++ b/uapi.go
@@ -235,7 +235,6 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
dummy = device.staticIdentity.publicKey.Equals(publicKey)
device.staticIdentity.mutex.RUnlock()
-
if dummy {
peer = &Peer{}
} else {