This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new b2b574b983 feat(plc4go): appendTransportUrl and ctx on GetConnection
b2b574b983 is described below
commit b2b574b98388a86ed837a398a746ebeef464771a
Author: Sebastian Rühl <[email protected]>
AuthorDate: Fri Nov 21 13:10:13 2025 +0100
feat(plc4go): appendTransportUrl and ctx on GetConnection
---
plc4go/internal/ads/Driver.go | 19 ++++++++++---------
plc4go/internal/bacnetip/Driver.go | 12 ++++++------
plc4go/internal/cbus/Driver.go | 22 +++++++++++-----------
plc4go/internal/eip/Driver.go | 24 ++++++++++++------------
plc4go/internal/knxnetip/Driver.go | 7 ++++---
plc4go/internal/modbus/AsciiDriver.go | 24 ++++++++++++------------
plc4go/internal/modbus/RtuDriver.go | 24 ++++++++++++------------
plc4go/internal/modbus/TcpDriver.go | 24 ++++++++++++------------
plc4go/internal/opcua/Driver.go | 26 +++++++++++++-------------
plc4go/internal/s7/Driver.go | 24 ++++++++++++------------
plc4go/internal/simulated/Driver.go | 11 ++++++-----
11 files changed, 110 insertions(+), 107 deletions(-)
diff --git a/plc4go/internal/ads/Driver.go b/plc4go/internal/ads/Driver.go
index 4600291e28..fc98734b32 100644
--- a/plc4go/internal/ads/Driver.go
+++ b/plc4go/internal/ads/Driver.go
@@ -58,7 +58,8 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Stringer("transportUrl", &transportUrl).
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
@@ -66,7 +67,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -78,10 +79,10 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -91,13 +92,13 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
// Create a new codec for taking care of encoding/decoding of messages
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
- configuration, err := model.ParseFromOptions(d.log, driverOptions)
+ configuration, err := model.ParseFromOptions(connectionLog,
driverOptions)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid driverOptions")
+ connectionLog.Error().Err(err).Msg("Invalid driverOptions")
return nil, errors.Wrap(err, "invalid configuration")
}
@@ -106,7 +107,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
if err != nil {
return nil, errors.Wrap(err, "couldn't create connection")
}
- d.log.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
+ connectionLog.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/bacnetip/Driver.go
b/plc4go/internal/bacnetip/Driver.go
index 30a45a8f23..09166cebb6 100644
--- a/plc4go/internal/bacnetip/Driver.go
+++ b/plc4go/internal/bacnetip/Driver.go
@@ -74,15 +74,15 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -99,7 +99,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
case *udp.Transport:
udpTransport = transport
default:
- d.log.Error().Stringer("transportUrl", &transportUrl).Msg("Only
udp supported at the moment")
+ connectionLog.Error().Stringer("transportUrl",
&transportUrl).Msg("Only udp supported at the moment")
return nil, errors.Errorf("couldn't find transport for given
transport url %#v", transportUrl)
}
@@ -107,11 +107,11 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
if err != nil {
return nil, errors.Wrap(err, "error getting application layer
message codec")
}
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
// Create the new connection
connection := NewConnection(codec, d.GetPlcTagHandler(), d.tm,
driverOptions)
- d.log.Debug().Msg("created connection, connecting now")
+ connectionLog.Debug().Msg("created connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/cbus/Driver.go b/plc4go/internal/cbus/Driver.go
index ae0c7745a3..28d09f2f2a 100644
--- a/plc4go/internal/cbus/Driver.go
+++ b/plc4go/internal/cbus/Driver.go
@@ -61,15 +61,15 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -81,26 +81,26 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
return nil, errors.Wrapf(err, "couldn't initialize transport
configuration for given transport url %s", transportUrl.String())
}
- configuration, err := ParseFromOptions(d.log, driverOptions)
+ configuration, err := ParseFromOptions(connectionLog, driverOptions)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid options")
+ connectionLog.Error().Err(err).Msg("Invalid options")
return nil, errors.Wrap(err, "Invalid options")
}
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
driverContext := NewDriverContext(configuration)
driverContext.awaitSetupComplete = d.awaitSetupComplete
@@ -112,9 +112,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
driverContext,
d.GetPlcTagHandler(),
d.tm, driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Msg("created connection, connecting now")
+ connectionLog.Debug().Msg("created connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/eip/Driver.go b/plc4go/internal/eip/Driver.go
index 99a2c88b9e..0831d379bc 100644
--- a/plc4go/internal/eip/Driver.go
+++ b/plc4go/internal/eip/Driver.go
@@ -59,15 +59,15 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get an the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -79,10 +79,10 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -91,19 +91,19 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
- configuration, err := ParseFromOptions(d.log, driverOptions)
+ configuration, err := ParseFromOptions(connectionLog, driverOptions)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid driverOptions")
+ connectionLog.Error().Err(err).Msg("Invalid driverOptions")
return nil, errors.Wrap(err, "Invalid driverOptions")
}
driverContext, err := NewDriverContext(configuration)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid driverOptions")
+ connectionLog.Error().Err(err).Msg("Invalid driverOptions")
return nil, errors.Wrap(err, "Invalid driverOptions")
}
driverContext.awaitSetupComplete = d.awaitSetupComplete
@@ -117,9 +117,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
d.GetPlcTagHandler(),
d.tm,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Msg("created connection, connecting now")
+ connectionLog.Debug().Msg("created connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/knxnetip/Driver.go
b/plc4go/internal/knxnetip/Driver.go
index ca7de6d105..f1a356295b 100644
--- a/plc4go/internal/knxnetip/Driver.go
+++ b/plc4go/internal/knxnetip/Driver.go
@@ -60,6 +60,7 @@ func (d *Driver) CheckQuery(query string) error {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
// Get an the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
@@ -71,7 +72,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
return nil, errors.Errorf("couldn't initialize transport
configuration for given transport url %#v", transportUrl)
@@ -82,9 +83,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance,
driverOptions,
d.GetPlcTagHandler(),
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Trace().
+ connectionLog.Trace().
Str("transport", transportUrl.String()).
Interface("connection", connection).
Msg("created new connection instance, trying to connect now")
diff --git a/plc4go/internal/modbus/AsciiDriver.go
b/plc4go/internal/modbus/AsciiDriver.go
index 6c6c926df7..c0a042b79b 100644
--- a/plc4go/internal/modbus/AsciiDriver.go
+++ b/plc4go/internal/modbus/AsciiDriver.go
@@ -56,15 +56,15 @@ func NewModbusAsciiDriver(_options ...options.WithOption)
*AsciiDriver {
}
func (d *AsciiDriver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get an the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -76,10 +76,10 @@ func (d *AsciiDriver) GetConnection(ctx context.Context,
transportUrl url.URL, t
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -92,7 +92,7 @@ func (d *AsciiDriver) GetConnection(ctx context.Context,
transportUrl url.URL, t
d.wg.Go(func() {
defer func() {
if err := recover(); err != nil {
- d.log.Error().
+ connectionLog.Error().
Str("stack", string(debug.Stack())).
Interface("err", err).
Msg("panic-ed")
@@ -101,14 +101,14 @@ func (d *AsciiDriver) GetConnection(ctx context.Context,
transportUrl url.URL, t
for {
msg := <-defaultChanel
adu := msg.(model.ModbusTcpADU)
- d.log.Debug().Interface("adu", adu).Msg("got message in
the default handler %s\n")
+ connectionLog.Debug().Interface("adu", adu).Msg("got
message in the default handler %s\n")
}
})
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
// If a unit-identifier was provided in the connection string use this,
otherwise use the default of 1
unitIdentifier := uint8(1)
@@ -119,7 +119,7 @@ func (d *AsciiDriver) GetConnection(ctx context.Context,
transportUrl url.URL, t
unitIdentifier = uint8(intValue)
}
}
- d.log.Debug().Uint8("unitIdentifier", unitIdentifier).Msg("using unit
identifier")
+ connectionLog.Debug().Uint8("unitIdentifier",
unitIdentifier).Msg("using unit identifier")
// Create the new connection
connection := NewConnection(
@@ -127,9 +127,9 @@ func (d *AsciiDriver) GetConnection(ctx context.Context,
transportUrl url.URL, t
codec,
driverOptions,
d.GetPlcTagHandler(),
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
+ connectionLog.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/modbus/RtuDriver.go
b/plc4go/internal/modbus/RtuDriver.go
index d8ab863acc..db52667226 100644
--- a/plc4go/internal/modbus/RtuDriver.go
+++ b/plc4go/internal/modbus/RtuDriver.go
@@ -56,15 +56,15 @@ func NewModbusRtuDriver(_options ...options.WithOption)
*RtuDriver {
}
func (d *RtuDriver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get an the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -76,10 +76,10 @@ func (d *RtuDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -92,7 +92,7 @@ func (d *RtuDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
d.wg.Go(func() {
defer func() {
if err := recover(); err != nil {
- d.log.Error().
+ connectionLog.Error().
Str("stack", string(debug.Stack())).
Interface("err", err).
Msg("panic-ed")
@@ -101,14 +101,14 @@ func (d *RtuDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
for {
msg := <-defaultChanel
adu := msg.(model.ModbusTcpADU)
- d.log.Debug().Interface("adu", adu).Msg("got message in
the default handler")
+ connectionLog.Debug().Interface("adu", adu).Msg("got
message in the default handler")
}
})
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
// If a unit-identifier was provided in the connection string use this,
otherwise use the default of 1
unitIdentifier := uint8(1)
@@ -119,16 +119,16 @@ func (d *RtuDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
unitIdentifier = uint8(intValue)
}
}
- d.log.Debug().Uint8("unitIdentifier", unitIdentifier).Msg("using unit
identifier")
+ connectionLog.Debug().Uint8("unitIdentifier",
unitIdentifier).Msg("using unit identifier")
// Create the new connection
connection := NewConnection(
unitIdentifier,
codec, driverOptions,
d.GetPlcTagHandler(),
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
+ connectionLog.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/modbus/TcpDriver.go
b/plc4go/internal/modbus/TcpDriver.go
index 421a585647..85070a935e 100644
--- a/plc4go/internal/modbus/TcpDriver.go
+++ b/plc4go/internal/modbus/TcpDriver.go
@@ -56,15 +56,15 @@ func NewModbusTcpDriver(_options ...options.WithOption)
*TcpDriver {
}
func (d *TcpDriver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get an the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -76,10 +76,10 @@ func (d *TcpDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -92,7 +92,7 @@ func (d *TcpDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
d.wg.Go(func() {
defer func() {
if err := recover(); err != nil {
- d.log.Error().
+ connectionLog.Error().
Str("stack", string(debug.Stack())).
Interface("err", err).
Msg("panic-ed")
@@ -101,14 +101,14 @@ func (d *TcpDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
for {
msg := <-defaultChanel
adu := msg.(model.ModbusTcpADU)
- d.log.Debug().Interface("adu", adu).Msg("got message in
the default handler")
+ connectionLog.Debug().Interface("adu", adu).Msg("got
message in the default handler")
}
})
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
// If a unit-identifier was provided in the connection string use this,
otherwise use the default of 1
unitIdentifier := uint8(1)
@@ -119,7 +119,7 @@ func (d *TcpDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
unitIdentifier = uint8(intValue)
}
}
- d.log.Debug().Uint8("unitIdentifier", unitIdentifier).Msg("using unit
identifier")
+ connectionLog.Debug().Uint8("unitIdentifier",
unitIdentifier).Msg("using unit identifier")
// Create the new connection
connection := NewConnection(
@@ -127,9 +127,9 @@ func (d *TcpDriver) GetConnection(ctx context.Context,
transportUrl url.URL, tra
codec,
driverOptions,
d.GetPlcTagHandler(),
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
+ connectionLog.Debug().Interface("connection", connection).Msg("created
connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/opcua/Driver.go b/plc4go/internal/opcua/Driver.go
index 51231dd750..5ddeae07a7 100644
--- a/plc4go/internal/opcua/Driver.go
+++ b/plc4go/internal/opcua/Driver.go
@@ -62,8 +62,8 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("numberTransports", len(transports)).
Int("numberDriverOptions", len(driverOptions)).
Msg("Get connection for transport url")
@@ -71,7 +71,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -84,10 +84,10 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -121,7 +121,7 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
}
// Create the configuration object.
- configuration, err := ParseFromOptions(d.log, driverOptions)
+ configuration, err := ParseFromOptions(connectionLog, driverOptions)
if err != nil {
return nil, errors.Wrap(err, "can't parse options")
}
@@ -133,15 +133,15 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
portAddition += ":" + transportPort
}
configuration.Endpoint = "opc." + transportCode + "://" + transportHost
+ portAddition + "" + transportEndpoint
- d.log.Debug().Interface("configuration", &configuration).Msg("working
with configuration")
+ connectionLog.Debug().Interface("configuration",
&configuration).Msg("working with configuration")
if securityPolicy := configuration.SecurityPolicy; securityPolicy != ""
&& securityPolicy != "None" {
- d.log.Trace().Str("securityPolicy",
securityPolicy).Msg("working with security policy")
+ connectionLog.Trace().Str("securityPolicy",
securityPolicy).Msg("working with security policy")
if err := configuration.openKeyStore(); err != nil {
return nil, errors.Wrap(err, "error opening key store")
}
} else {
- d.log.Trace().Msg("no security policy")
+ connectionLog.Trace().Msg("no security policy")
}
driverContext := NewDriverContext(configuration)
@@ -150,9 +150,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
// Create the new connection
connection := NewConnection(
@@ -161,9 +161,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
driverContext,
d.GetPlcTagHandler(),
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Msg("created connection, connecting now")
+ connectionLog.Debug().Msg("created connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/s7/Driver.go b/plc4go/internal/s7/Driver.go
index 543aeaaa1f..ff6c854dda 100644
--- a/plc4go/internal/s7/Driver.go
+++ b/plc4go/internal/s7/Driver.go
@@ -59,15 +59,15 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
}
func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL,
transports map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
- d.log.Debug().
- Stringer("transportUrl", &transportUrl).
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
+ connectionLog.Debug().
Int("nTransports", len(transports)).
Int("nDriverOptions", len(driverOptions)).
Msg("Get connection for transport url with nTransports
transport(s) and nDriverOptions option(s)")
// Get the transport specified in the url
transport, ok := transports[transportUrl.Scheme]
if !ok {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Str("scheme", transportUrl.Scheme).
Msg("We couldn't find a transport for scheme")
@@ -79,10 +79,10 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
transportInstance, err := transport.CreateTransportInstance(
transportUrl,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
if err != nil {
- d.log.Error().
+ connectionLog.Error().
Stringer("transportUrl", &transportUrl).
Strs("defaultTcpPort", driverOptions["defaultTcpPort"]).
Msg("We couldn't create a transport instance for port")
@@ -91,19 +91,19 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
codec := NewMessageCodec(
transportInstance,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Interface("codec", codec).Msg("working with codec")
+ connectionLog.Debug().Interface("codec", codec).Msg("working with
codec")
- configuration, err := ParseFromOptions(d.log, driverOptions)
+ configuration, err := ParseFromOptions(connectionLog, driverOptions)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid driverOptions")
+ connectionLog.Error().Err(err).Msg("Invalid driverOptions")
return nil, errors.Wrap(err, "Invalid driverOptions")
}
driverContext, err := NewDriverContext(configuration)
if err != nil {
- d.log.Error().Err(err).Msg("Invalid driverOptions")
+ connectionLog.Error().Err(err).Msg("Invalid driverOptions")
return nil, errors.Wrap(err, "Invalid driverOptions")
}
driverContext.awaitSetupComplete = d.awaitSetupComplete
@@ -117,9 +117,9 @@ func (d *Driver) GetConnection(ctx context.Context,
transportUrl url.URL, transp
d.GetPlcTagHandler(),
d.tm,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Debug().Msg("created connection, connecting now")
+ connectionLog.Debug().Msg("created connection, connecting now")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
diff --git a/plc4go/internal/simulated/Driver.go
b/plc4go/internal/simulated/Driver.go
index e86f4b3b3b..de2aa99c95 100644
--- a/plc4go/internal/simulated/Driver.go
+++ b/plc4go/internal/simulated/Driver.go
@@ -52,22 +52,23 @@ func NewDriver(_options ...options.WithOption)
plc4go.PlcDriver {
return driver
}
-func (d *Driver) GetConnection(ctx context.Context, _ url.URL, _
map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
+func (d *Driver) GetConnection(ctx context.Context, transportUrl url.URL, _
map[string]transports.Transport, driverOptions map[string][]string)
(plc4go.PlcConnection, error) {
+ connectionLog := d.log.With().Ctx(ctx).Str("transportUrl",
transportUrl.String()).Logger()
connection := NewConnection(
NewDevice(
"test",
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options,
options.WithCustomLogger(connectionLog))...,
),
d.GetPlcTagHandler(),
d.valueHandler,
driverOptions,
- append(d._options, options.WithCustomLogger(d.log))...,
+ append(d._options, options.WithCustomLogger(connectionLog))...,
)
- d.log.Trace().Interface("connection", connection).Msg("Connecting")
+ connectionLog.Trace().Interface("connection",
connection).Msg("Connecting")
if err := connection.Connect(ctx); err != nil {
return nil, errors.Wrap(err, "Error connecting connection")
}
- d.log.Trace().Interface("connection", connection).Msg("Connected")
+ connectionLog.Trace().Interface("connection",
connection).Msg("Connected")
return connection, nil
}