Skip to content

Commit

Permalink
Add capability to set loglevel to trace during runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Arpad Kiss <[email protected]>
  • Loading branch information
arp-est committed Oct 11, 2024
1 parent 7421855 commit 78136fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {
if err := envconfig.Process("nsm", rootConf); err != nil {
logger.Fatalf("error processing rootConf from env: %+v", err)
}
setLogLevel(rootConf.LogLevel)
setupLogLevel(ctx, rootConf.LogLevel)
logger.Infof("rootConf: %+v", rootConf)

// ********************************************************************************
Expand Down Expand Up @@ -224,10 +224,14 @@ func main() {
}
}

func setLogLevel(level string) {
func setupLogLevel(ctx context.Context, level string) {
l, err := logrus.ParseLevel(level)
if err != nil {
logrus.Fatalf("invalid log level %s", level)
}
logrus.SetLevel(l)
logruslogger.SetupLevelChangeOnSignal(ctx, map[os.Signal]logrus.Level{
syscall.SIGUSR1: logrus.TraceLevel,
syscall.SIGUSR2: l,
})
}

0 comments on commit 78136fd

Please sign in to comment.