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 2023/06/15 13:41:33 UTC
[plc4x] 02/02: test(plc4go/spi): add env var to enable high precision timestamps
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
commit 2ca899206f91e7dcf2da67af314e4e70c54921fa
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 15 15:33:44 2023 +0200
test(plc4go/spi): add env var to enable high precision timestamps
---
plc4go/spi/testutils/TestUtils.go | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/plc4go/spi/testutils/TestUtils.go b/plc4go/spi/testutils/TestUtils.go
index 2e0752a932..3829067a1c 100644
--- a/plc4go/spi/testutils/TestUtils.go
+++ b/plc4go/spi/testutils/TestUtils.go
@@ -21,14 +21,14 @@ package testutils
import (
"context"
+ "github.com/apache/plc4x/plc4go/spi/options"
+ "github.com/apache/plc4x/plc4go/spi/pool"
+ "github.com/apache/plc4x/plc4go/spi/utils"
"os"
"runtime/debug"
"strings"
"testing"
-
- "github.com/apache/plc4x/plc4go/spi/options"
- "github.com/apache/plc4x/plc4go/spi/pool"
- "github.com/apache/plc4x/plc4go/spi/utils"
+ "time"
"github.com/ajankovic/xdiff"
"github.com/ajankovic/xdiff/parser"
@@ -115,9 +115,18 @@ func TestContext(t *testing.T) context.Context {
return ctx
}
+var highLogPrecision bool
+
+func init() {
+ highLogPrecision = os.Getenv("PLC4X_TEST_HIGH_TEST_LOG_PRECISION") == "true"
+ if highLogPrecision {
+ zerolog.TimeFieldFormat = time.RFC3339Nano
+ }
+}
+
// ProduceTestingLogger produces a logger which redirects to testing.T
func ProduceTestingLogger(t *testing.T) zerolog.Logger {
- return zerolog.New(
+ logger := zerolog.New(
zerolog.NewConsoleWriter(
zerolog.ConsoleTestWriter(t),
func(w *zerolog.ConsoleWriter) {
@@ -128,9 +137,17 @@ func ProduceTestingLogger(t *testing.T) zerolog.Logger {
if onJenkins || onGithubAction || onCI {
w.NoColor = true
}
+
+ },
+ func(w *zerolog.ConsoleWriter) {
+ w.TimeFormat = time.StampNano
},
),
)
+ if highLogPrecision {
+ logger = logger.With().Timestamp().Logger()
+ }
+ return logger
}
// EnrichOptionsWithOptionsForTesting appends options useful for testing to config.WithOption s