forked from koding/kite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_unix.go
44 lines (37 loc) · 889 Bytes
/
logger_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// +build !windows
package kite
import (
"os"
"os/signal"
"syscall"
)
// SetupSignalHandler listens to signals and toggles the log level to DEBUG
// mode when it received a SIGUSR2 signal. Another SIGUSR2 toggles the log
// level back to the old level.
func (k *Kite) SetupSignalHandler() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGUSR2)
go func() {
for s := range c {
k.Log.Info("Got signal: %s", s)
if debugMode {
// toogle back to old settings.
k.Log.Info("Disabling debug mode")
if k.SetLogLevel == nil {
k.Log.Error("SetLogLevel is not defined")
continue
}
k.SetLogLevel(getLogLevel())
debugMode = false
} else {
k.Log.Info("Enabling debug mode")
if k.SetLogLevel == nil {
k.Log.Error("SetLogLevel is not defined")
continue
}
k.SetLogLevel(DEBUG)
debugMode = true
}
}
}()
}