diff --git a/main.go b/main.go index 54de9f33..a18d0124 100644 --- a/main.go +++ b/main.go @@ -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, @@ -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 @@ -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