Provider Auth: use base logger if available (#26138)
This commit is contained in:
parent
6ecf041d9a
commit
31bb62148d
14 changed files with 45 additions and 33 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue