-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
61 lines (53 loc) · 1.18 KB
/
utils.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"os"
"os/signal"
"strings"
"syscall"
"time"
log "github.com/sirupsen/logrus"
)
// exitSignalHandling wait for interrump signal to gracefully shutdown the server with a timeout configured inside context
func exitSignalHandling(cancel context.CancelFunc) <-chan interface{} {
quit := make(chan os.Signal, 10)
exiting := make(chan interface{})
signal.Notify(quit, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
go func() {
<-quit
log.Info("Received exit signal; stopping jagozzi")
exiting <- nil
cancel()
}()
return exiting
}
func exitTimeout(ctx context.Context) {
<-ctx.Done()
after := time.After(5 * time.Second)
<-after
log.Error("jagozzi: timeout while exiting")
os.Exit(1)
}
func applyLogLevel(level *string) {
if guiConsumer != nil && *guiConsumer {
log.SetLevel(log.PanicLevel)
return
}
if level == nil {
return
}
switch strings.ToLower(*level) {
case "info":
log.SetLevel(log.InfoLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "debug":
log.SetLevel(log.DebugLevel)
case "error":
log.SetLevel(log.ErrorLevel)
case "fatal":
log.SetLevel(log.FatalLevel)
case "panic":
log.SetLevel(log.PanicLevel)
}
}