summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Fox <[email protected]>2021-08-21 22:33:13 +0100
committerPeter Fox <[email protected]>2021-09-06 22:24:22 +0100
commit95f36a157cdf25f7dc40bd5fa963251231c211ef (patch)
tree20d61af5efb9e823c27b09817f9c3c0e59636971 /tests
parent6749db4a2d39fa70b426bcf50edf66a176c07f57 (diff)
Lets Zap fields to be used as arguments to logger
Diffstat (limited to 'tests')
-rw-r--r--tests/plugins/logger/plugin.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/plugins/logger/plugin.go b/tests/plugins/logger/plugin.go
index aa62f2b3..e2227ec9 100644
--- a/tests/plugins/logger/plugin.go
+++ b/tests/plugins/logger/plugin.go
@@ -6,6 +6,8 @@ import (
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "go.uber.org/zap"
+ core "go.uber.org/zap/zapcore"
)
type Plugin struct {
@@ -13,6 +15,14 @@ type Plugin struct {
log logger.Logger
}
+type Loggable struct {
+}
+
+func (l *Loggable) MarshalLogObject(encoder core.ObjectEncoder) error {
+ encoder.AddString("error", "Example marshaller error")
+ return nil
+}
+
func (p1 *Plugin) Init(cfg config.Configurer, log logger.Logger) error {
p1.config = cfg
p1.log = log
@@ -26,6 +36,20 @@ func (p1 *Plugin) Serve() chan error {
p1.log.Debug("error", "test", errors.E(errors.Str("test")))
p1.log.Warn("error", "test", errors.E(errors.Str("test")))
+ field := zap.String("error", "Example field error")
+
+ p1.log.Error("error", field)
+ p1.log.Info("error", field)
+ p1.log.Debug("error", field)
+ p1.log.Warn("error", field)
+
+ marshalledObject := Loggable{}
+
+ p1.log.Error("error", marshalledObject)
+ p1.log.Info("error", marshalledObject)
+ p1.log.Debug("error", marshalledObject)
+ p1.log.Warn("error", marshalledObject)
+
p1.log.Error("error", "test")
p1.log.Info("error", "test")
p1.log.Debug("error", "test")