Loki: Fix healthcheck logger always appending endpoint (#96531)

* Loki: Fix healthcheck logger always appending `endpoint`

* add test
This commit is contained in:
Sven Grossmann
2024-11-15 12:51:52 +01:00
committed by GitHub
parent 927d0dddfe
commit 5965aa9aca
3 changed files with 16 additions and 3 deletions

View File

@ -186,8 +186,9 @@ func (l *logWrapper) Level() sdklog.Level {
}
func (l *logWrapper) With(args ...any) sdklog.Logger {
l.logger = l.logger.New(args...)
return l
return &logWrapper{
logger: l.logger.New(args...),
}
}
func (l *logWrapper) FromContext(ctx context.Context) sdklog.Logger {

View File

@ -5,6 +5,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
@ -62,3 +63,14 @@ func TestNewPlugin(t *testing.T) {
})
}
}
func TestLogger(t *testing.T) {
t.Run("logger.With should create a new logger", func(t *testing.T) {
wrapper := &logWrapper{
logger: log.New("test"),
}
newLogger := wrapper.With("key", "value")
require.NotSame(t, newLogger.(*logWrapper).logger, wrapper.logger, "`With` should not return the same instance")
})
}