Skip to content

Commit

Permalink
Merge pull request #523 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 881ffcd + 7ec0c9a commit 00f5b50
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@ func main() {
if err := envconfig.Process("nsm", config); err != nil {
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)

// Configure Open Telemetry
Expand All @@ -125,7 +119,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 @@ -237,3 +231,15 @@ func defaultURL(listenOn []url.URL) *url.URL {
}
return &listenOn[0]
}

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 00f5b50

Please sign in to comment.