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 f788dd5 commit 72a55ef
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 @@ -140,7 +140,7 @@ func main() {
logrus.Fatalf("error processing config from env: %+v", err)
}

setLogLevel(config.LogLevel)
setupLogLevel(ctx, config.LogLevel)

log.FromContext(ctx).Infof("Config: %#v", config)
log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 1: get config from environment")
Expand Down Expand Up @@ -513,10 +513,14 @@ func registerEndpoint(ctx context.Context, cfg *Config, source *workloadapi.X509
return err
}

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 72a55ef

Please sign in to comment.