Skip to content

Commit

Permalink
Merge pull request #705 from Nordix/arp_dynloglevel
Browse files Browse the repository at this point in the history
Add capability to set loglevel to trace during runtime
  • Loading branch information
denis-tingaikin authored Oct 14, 2024
2 parents 9c6dd83 + 4f620e3 commit 43e6601
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 @@ -143,11 +143,7 @@ func main() {
logrus.Fatal(err.Error())
}

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 @@ -160,7 +156,7 @@ func main() {
metricExporter := opentelemetry.InitOPTLMetricExporter(ctx, collectorAddress, config.MetricsExportInterval)
o := opentelemetry.Init(ctx, spanExporter, metricExporter, config.Name)
defer func() {
if err = o.Close(); err != nil {
if err := o.Close(); err != nil {
log.FromContext(ctx).Error(err.Error())
}
}()
Expand Down Expand Up @@ -334,3 +330,15 @@ func notifyContext() (context.Context, context.CancelFunc) {
syscall.SIGQUIT,
)
}

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 43e6601

Please sign in to comment.