pkg: support structured logger

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee
2018-04-16 03:57:43 -07:00
parent bdbed26f64
commit 0dad8abb6f
5 changed files with 36 additions and 12 deletions

View File

@ -21,6 +21,8 @@ import (
"os/signal"
"sync"
"syscall"
"go.uber.org/zap"
)
// InterruptHandler is a function that is called on receiving a
@ -43,7 +45,7 @@ func RegisterInterruptHandler(h InterruptHandler) {
}
// HandleInterrupts calls the handler functions on receiving a SIGINT or SIGTERM.
func HandleInterrupts() {
func HandleInterrupts(lg *zap.Logger) {
notifier := make(chan os.Signal, 1)
signal.Notify(notifier, syscall.SIGINT, syscall.SIGTERM)
@ -57,7 +59,11 @@ func HandleInterrupts() {
interruptExitMu.Lock()
plog.Noticef("received %v signal, shutting down...", sig)
if lg != nil {
lg.Info("received signal; shutting down", zap.String("signal", sig.String()))
} else {
plog.Noticef("received %v signal, shutting down...", sig)
}
for _, h := range ihs {
h()