Provider Auth: use base logger if available (#26138)

This commit is contained in:
andig 2025-12-22 10:22:10 +01:00 • committed by GitHub
parent 6ecf041d9a
commit 31bb62148d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 45 additions and 33 deletions

View file

@ -92,7 +92,7 @@ func NewOAuth(ctx context.Context, name, device string, oc *oauth2.Config, opts
return instance, nil
}
log := util.NewLogger("oauth-" + hash)
log := util.ContextLoggerWithDefault(ctx, util.NewLogger("oauth-"+hash))
if client, ok := ctx.Value(oauth2.HTTPClient).(*http.Client); client == nil || !ok {
ctx = context.WithValue(ctx, oauth2.HTTPClient, request.NewClient(log))

View file

@ -1,7 +1,6 @@
package plugin
import (
"context"
"fmt"
"math"
"strconv"
@ -35,16 +34,6 @@ func knownErrors(b []byte) error {
}
}
func contextLogger(ctx context.Context, log *util.Logger) *util.Logger {
if ctx != nil {
if l, ok := ctx.Value(util.CtxLogger).(*util.Logger); ok {
log = l
}
}
return log
}
// parseFloat rejects NaN and Inf values
func parseFloat(payload string) (float64, error) {
f, err := strconv.ParseFloat(payload, 64)

View file

@ -61,7 +61,7 @@ func NewHTTPPluginFromConfig(ctx context.Context, other map[string]any) (Plugin,
return nil, errors.New("missing uri")
}
log := contextLogger(ctx, util.NewLogger("http"))
log := util.ContextLoggerWithDefault(ctx, util.NewLogger("http"))
p := NewHTTP(
log,
strings.ToUpper(cc.Method),

View file

@ -59,7 +59,7 @@ func NewModbusFromConfig(ctx context.Context, other map[string]any) (Plugin, err
// set non-default connect delay
conn.ConnectDelay(cc.ConnectDelay)
log := contextLogger(ctx, util.NewLogger("modbus"))
log := util.ContextLoggerWithDefault(ctx, util.NewLogger("modbus"))
conn.Logger(log.TRACE)
if err := cc.Register.Error(); err != nil {

View file

@ -42,7 +42,7 @@ func NewMqttPluginFromConfig(ctx context.Context, other map[string]any) (Plugin,
return nil, err
}
log := contextLogger(ctx, util.NewLogger("mqtt"))
log := util.ContextLoggerWithDefault(ctx, util.NewLogger("mqtt"))
client, err := mqtt.RegisteredClientOrDefault(log, cc.Config)
if err != nil {

View file

@ -41,7 +41,7 @@ func NewWatchDogFromConfig(ctx context.Context, other map[string]any) (Plugin, e
o := &watchdogPlugin{
ctx: ctx,
log: contextLogger(ctx, util.NewLogger("watchdog")),
log: util.ContextLoggerWithDefault(ctx, util.NewLogger("watchdog")),
reset: cc.Reset,
initial: cc.Initial,
set: cc.Set,