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 Oct 11, 2024
1 parent 0b1a465 commit 5408a80
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ func main() {
logrus.Fatalf("error processing config from env: %+v", err)
}

l, err := logrus.ParseLevel(config.LogLevel)
if err != nil {
logrus.Fatalf("invalid log level %s", config.LogLevel)
}
logrus.SetLevel(l)
setupLogLevel(ctx, config.LogLevel)

log.FromContext(ctx).Infof("Config: %#v", config)

Expand All @@ -118,7 +114,7 @@ func main() {
metricExporter := opentelemetry.InitOPTLMetricExporter(ctx, collectorAddress, config.MetricsExportInterval)
o := opentelemetry.Init(ctx, spanExporter, metricExporter, "registry-proxy-dns")
defer func() {
if err = o.Close(); err != nil {
if err := o.Close(); err != nil {
log.FromContext(ctx).Error(err.Error())
}
}()
Expand Down Expand Up @@ -196,3 +192,15 @@ func exitOnErr(ctx context.Context, cancel context.CancelFunc, errCh <-chan erro
cancel()
}(ctx, errCh)
}

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

0 comments on commit 5408a80

Please sign in to comment.