mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-03 13:10:42 +00:00
39 lines
746 B
Go
39 lines
746 B
Go
// +build !windows
|
|
|
|
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"go.uber.org/zap/zapcore"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func logLevelSignal() {
|
|
c := make(chan os.Signal)
|
|
signal.Notify(c, syscall.SIGUSR1, syscall.SIGUSR2)
|
|
fmt.Println("notify receive signal")
|
|
|
|
go func() {
|
|
for s := range c {
|
|
fmt.Println("receive signal ", s.String())
|
|
switch s {
|
|
case syscall.SIGUSR1:
|
|
cur := atomicLevel.Level()
|
|
if (cur - 1) >= zapcore.DebugLevel {
|
|
atomicLevel.SetLevel(zapcore.Level(cur - 1))
|
|
}
|
|
case syscall.SIGUSR2:
|
|
cur := atomicLevel.Level()
|
|
if (cur + 1) <= zapcore.FatalLevel {
|
|
atomicLevel.SetLevel(zapcore.Level(cur + 1))
|
|
}
|
|
default:
|
|
}
|
|
|
|
fmt.Println("debug level change to ", atomicLevel.String())
|
|
}
|
|
}()
|
|
}
|