From f6a5dccaf56b25202830949b18195d106aaf6c0c Mon Sep 17 00:00:00 2001 From: Spazzy Date: Wed, 29 May 2024 13:28:16 +0200 Subject: [PATCH] fix: add plugin log level This will set the plugin log level to the same level that is configured for aether Signed-off-by: Spazzy --- pkg/plugin/exporter.go | 2 +- pkg/plugin/log.go | 23 +++++++++++++++++++++++ pkg/plugin/source.go | 2 +- pkg/source/manager.go | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 pkg/plugin/log.go diff --git a/pkg/plugin/exporter.go b/pkg/plugin/exporter.go index 7db0c78..5fa3340 100644 --- a/pkg/plugin/exporter.go +++ b/pkg/plugin/exporter.go @@ -137,7 +137,7 @@ func (e *ExportPluginSystem) Load(ctx context.Context) error { Logger: hclog.New(&hclog.LoggerOptions{ Name: "exporter", Output: os.Stdout, - Level: hclog.Debug, + Level: getLogLevel(), JSONFormat: true, }), }) diff --git a/pkg/plugin/log.go b/pkg/plugin/log.go new file mode 100644 index 0000000..ed5803e --- /dev/null +++ b/pkg/plugin/log.go @@ -0,0 +1,23 @@ +package plugin + +import ( + "github.com/hashicorp/go-hclog" + "github.com/re-cinq/aether/pkg/config" +) + +// getLogLevel is a helper function to get the log level from the config +func getLogLevel() hclog.Level { + level := config.AppConfig().LogLevel + switch level { + case "debug": + return hclog.Debug + case "info": + return hclog.Info + case "warn": + return hclog.Warn + case "error": + return hclog.Error + default: + return hclog.Info + } +} diff --git a/pkg/plugin/source.go b/pkg/plugin/source.go index 3aa23cb..8accf9b 100644 --- a/pkg/plugin/source.go +++ b/pkg/plugin/source.go @@ -166,7 +166,7 @@ func (s *SourcePluginSystem) Load(ctx context.Context) error { Logger: hclog.New(&hclog.LoggerOptions{ Name: "source", Output: os.Stdout, - Level: hclog.Debug, + Level: getLogLevel(), JSONFormat: true, }), }) diff --git a/pkg/source/manager.go b/pkg/source/manager.go index 1140cca..97e1c54 100644 --- a/pkg/source/manager.go +++ b/pkg/source/manager.go @@ -91,7 +91,7 @@ func (m *Manager) Fetch(ctx context.Context) { wg.Done() return } - + logger.Debug("publishing instances", "instance count", len(instances)) err = m.publishInstances(instances) if err != nil { logger.Error("failed publishing instances", "error", err)