You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2026/10/19 15:14:37 UTC
(plc4x) branch develop updated: refactor(plc4go): move the zerolog PLC message marshaller to spi/utils
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 90f6bec9e4 refactor(plc4go): move the zerolog PLC message marshaller to spi/utils
90f6bec9e4 is described below
commit 90f6bec9e425ecab3ed1917a784aa6e70ca0773e
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Oct 19 16:21:11 2026 +0200
refactor(plc4go): move the zerolog PLC message marshaller to spi/utils
pkg/api/logging was deprecated ("use options to configure logging"), but
the options only configure the logger; nothing replaced the zerolog
interface marshaller that renders Serializable PLC messages as JSON,
string, XML or bytes, so users of it (spi/testutils, downstream code)
were stuck on a deprecated package.
The package is removed and the marshaller moves to spi/utils, next to
the Serializable and write buffer types it builds on:
ZerologMessageInterfaceMarshalFunc, ZerologDefaultInterfaceMarshalFunc,
ZerologInterfacePLCMessageFormat and the PLCMessageAs* formats keep
their names. The 1.0.0 migration guide shows the new import.
---
plc4go/spi/testutils/TestUtils.go | 5 ++--
.../utils}/ZerologInterfaceMarshal.go | 32 +++++++++++-----------
.../pages/migrations/0.13.1-to-1.0.0/plc4go.adoc | 26 ------------------
3 files changed, 18 insertions(+), 45 deletions(-)
diff --git a/plc4go/spi/testutils/TestUtils.go b/plc4go/spi/testutils/TestUtils.go
index b53ef33f03..2be8dd0434 100644
--- a/plc4go/spi/testutils/TestUtils.go
+++ b/plc4go/spi/testutils/TestUtils.go
@@ -39,7 +39,6 @@ import (
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/assert"
- "github.com/apache/plc4x/plc4go/pkg/api/logging"
"github.com/apache/plc4x/plc4go/spi/errors"
"github.com/apache/plc4x/plc4go/spi/options"
"github.com/apache/plc4x/plc4go/spi/pool"
@@ -328,8 +327,8 @@ func ProduceTestingLogger(t TestingLog) zerolog.Logger {
}
})
interfaceMarshallerSetter.Do(func() {
- logging.ZerologInterfacePLCMessageFormat = logging.PLCMessageAsString
- zerolog.InterfaceMarshalFunc = logging.ZerologMessageInterfaceMarshalFunc
+ utils.ZerologInterfacePLCMessageFormat = utils.PLCMessageAsString
+ zerolog.InterfaceMarshalFunc = utils.ZerologMessageInterfaceMarshalFunc
})
logger = logger.With().Stack().Logger()
return logger
diff --git a/plc4go/pkg/api/logging/ZerologInterfaceMarshal.go b/plc4go/spi/utils/ZerologInterfaceMarshal.go
similarity index 80%
rename from plc4go/pkg/api/logging/ZerologInterfaceMarshal.go
rename to plc4go/spi/utils/ZerologInterfaceMarshal.go
index 443b777355..bcab3381b4 100644
--- a/plc4go/pkg/api/logging/ZerologInterfaceMarshal.go
+++ b/plc4go/spi/utils/ZerologInterfaceMarshal.go
@@ -17,8 +17,7 @@
* under the License.
*/
-// Deprecated: use options to configure logging
-package logging
+package utils
import (
"context"
@@ -27,7 +26,6 @@ import (
"github.com/rs/zerolog"
"github.com/apache/plc4x/plc4go/spi/errors"
- "github.com/apache/plc4x/plc4go/spi/utils"
)
// PLCMessageFormat defines the format of the PLCMessage that is logged
@@ -50,14 +48,16 @@ var ZerologInterfacePLCMessageFormat = PLCMessageAsJSON
// ZerologDefaultInterfaceMarshalFunc is the default marshal function used by zerolog
var ZerologDefaultInterfaceMarshalFunc = zerolog.InterfaceMarshalFunc
-// ZerologMessageInterfaceMarshalFunc is the marshal function used by zerolog to serialize PLCMessages.
-// To use it just do a zerolog.InterfaceMarshalFunc = ZerologMessageInterfaceMarshalFunc in a init function.
+// ZerologMessageInterfaceMarshalFunc is the marshal function used by zerolog to serialize PLCMessages
+// (Serializable values) in the format set by ZerologInterfacePLCMessageFormat; anything else goes to
+// ZerologDefaultInterfaceMarshalFunc. To use it set zerolog.InterfaceMarshalFunc =
+// ZerologMessageInterfaceMarshalFunc, e.g. in an init function.
var ZerologMessageInterfaceMarshalFunc = func(v any) ([]byte, error) {
- if plcMessage, ok := v.(utils.Serializable); ok {
+ if plcMessage, ok := v.(Serializable); ok {
switch ZerologInterfacePLCMessageFormat {
case PLCMessageAsJSON:
- jsonWriteBuffer := utils.NewJsonWriteBuffer(
- utils.WithJsonWriteBufferDefaultIdent(false),
+ jsonWriteBuffer := NewJsonWriteBuffer(
+ WithJsonWriteBufferDefaultIdent(false),
)
if err := plcMessage.SerializeWithWriteBuffer(context.Background(), jsonWriteBuffer); err != nil {
return nil, errors.Wrap(err, "error serializing PLCMessage")
@@ -73,11 +73,11 @@ var ZerologMessageInterfaceMarshalFunc = func(v any) ([]byte, error) {
}
return b, nil
case PLCMessageAsString:
- boxWriteBuffer := utils.NewWriteBufferBoxBased(
- utils.WithWriteBufferBoxBasedMergeSingleBoxes(),
- utils.WithWriteBufferBoxBasedOmitEmptyBoxes(),
- utils.WithWriteBufferBoxBasedDesiredWidth(200),
- utils.WithWriteBufferBoxBasedPrintPosLengthFooter(),
+ boxWriteBuffer := NewWriteBufferBoxBased(
+ WithWriteBufferBoxBasedMergeSingleBoxes(),
+ WithWriteBufferBoxBasedOmitEmptyBoxes(),
+ WithWriteBufferBoxBasedDesiredWidth(200),
+ WithWriteBufferBoxBasedPrintPosLengthFooter(),
)
if err := plcMessage.SerializeWithWriteBuffer(context.Background(), boxWriteBuffer); err != nil {
return nil, errors.Wrap(err, "error serializing PLCMessage")
@@ -85,8 +85,8 @@ var ZerologMessageInterfaceMarshalFunc = func(v any) ([]byte, error) {
boxString := boxWriteBuffer.GetBox().String()
return json.Marshal(boxString)
case PLCMessageAsXML:
- xmlWriteBuffer := utils.NewXmlWriteBuffer(
- utils.WithXmlWriteBufferDefaultIdent(false),
+ xmlWriteBuffer := NewXmlWriteBuffer(
+ WithXmlWriteBufferDefaultIdent(false),
)
if err := plcMessage.SerializeWithWriteBuffer(context.Background(), xmlWriteBuffer); err != nil {
return nil, errors.Wrap(err, "error serializing PLCMessage")
@@ -94,7 +94,7 @@ var ZerologMessageInterfaceMarshalFunc = func(v any) ([]byte, error) {
xmlString := xmlWriteBuffer.GetXmlString()
return json.Marshal(xmlString)
case PLCMessageAsByte:
- byteWriteBuffer := utils.NewWriteBufferByteBased()
+ byteWriteBuffer := NewWriteBufferByteBased()
if err := plcMessage.SerializeWithWriteBuffer(context.Background(), byteWriteBuffer); err != nil {
return nil, errors.Wrap(err, "error serializing PLCMessage")
}
diff --git a/website/asciidoc/modules/users/pages/migrations/0.13.1-to-1.0.0/plc4go.adoc b/website/asciidoc/modules/users/pages/migrations/0.13.1-to-1.0.0/plc4go.adoc
index 25501c588e..ae22c93f97 100644
--- a/website/asciidoc/modules/users/pages/migrations/0.13.1-to-1.0.0/plc4go.adoc
+++ b/website/asciidoc/modules/users/pages/migrations/0.13.1-to-1.0.0/plc4go.adoc
@@ -194,32 +194,6 @@ remotes that silently reap idle connections - a half-open TCP connection is unde
first write fails. Connections that report active subscription handles are exempt from the TTL,
because their subscription state lives on the connection.
-== The `logging` package
-
-`pkg/api/logging` no longer sets or resets the global zerolog level. `ErrorLevel()`, `WarnLevel()`,
-`InfoLevel()`, `DebugLevel()`, `TraceLevel()` and `ResetLogging()` are gone, together with the
-`init()` that used to force the global logger to error level the moment the package was imported.
-
-That `init()` was the real problem: importing a PLC4X package changed the logging of the whole
-process.
-
-Pass a logger to PLC4X instead, which is explicit and scoped to the connection:
-
-[source,go]
-----
-// 1.0.0
-logger := zerolog.New(os.Stderr).Level(zerolog.DebugLevel)
-connection, err := driverManager.GetConnection(ctx, connectionString,
- options.WithCustomLogger(logger))
-----
-
-If you relied on PLC4X quietening zerolog for you, set the level yourself:
-
-[source,go]
-----
-zerolog.SetGlobalLevel(zerolog.ErrorLevel)
-----
-
== Connection-string options need their transport prefix
PLC4Go read a transport's options *unprefixed*, while PLC4J declares them on the transport and