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 <arpad.a.kiss@est.tech>
  • Loading branch information
arp-est committed Sep 19, 2024
1 parent d2ba1ce commit d4f4d81
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func main() {
// ********************************************************************************
// setup context to catch signals
// ********************************************************************************
logChangeChannel := make(chan os.Signal, 1)
signal.Notify(logChangeChannel, syscall.SIGUSR1, syscall.SIGUSR2)
ctx, cancel := signal.NotifyContext(
context.Background(),
os.Interrupt,
Expand Down Expand Up @@ -135,6 +137,7 @@ func main() {
logrus.SetLevel(level)
log.EnableTracing(true)
log.FromContext(ctx).WithField("duration", time.Since(now)).Infof("completed phase 1: get config from environment")
go handleLogChangeSignal(ctx, logChangeChannel, level)

// ********************************************************************************
// Configure Open Telemetry
Expand Down Expand Up @@ -338,6 +341,25 @@ func main() {
<-cleanupDoneCh
}

func handleLogChangeSignal(ctx context.Context, ch chan os.Signal, logLevel logrus.Level) {
OUT:
for {
select {
case <-ctx.Done():
break OUT
case sig := <-ch:
switch sig {
case syscall.SIGUSR1:
log.FromContext(ctx).Infof("Setting log level to %s", logrus.TraceLevel.String())
logrus.SetLevel(logrus.TraceLevel)
case syscall.SIGUSR2:
log.FromContext(ctx).Infof("Setting log level to %s", logLevel.String())
logrus.SetLevel(logLevel)
}
}
}
}

func setupDeviceMap(ctx context.Context, cfg *config.Config) map[string]string {
if cfg.DeviceSelectorFile == "" {
return nil
Expand Down

0 comments on commit d4f4d81

Please sign in to comment.