summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/plugins/logger/logger_test.go71
-rw-r--r--tests/plugins/logger/plugin.go2
2 files changed, 72 insertions, 1 deletions
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index 174ee743..05ca2d53 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -357,3 +357,74 @@ func httpEcho(t *testing.T) {
err = r.Body.Close()
assert.NoError(t, err)
}
+
+func TestMarshalObjectLogging(t *testing.T) {
+ container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
+ if err != nil {
+ t.Fatal(err)
+ }
+ // config plugin
+ vp := &config.Viper{}
+ vp.Path = "configs/.rr-file-logger.yaml"
+ vp.Prefix = "rr"
+
+ err = container.RegisterAll(
+ vp,
+ &Plugin{},
+ &logger.ZapLogger{},
+ )
+ assert.NoError(t, err)
+
+ err = container.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ errCh, err := container.Serve()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ // stop by CTRL+C
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, os.Interrupt)
+
+ stopCh := make(chan struct{}, 1)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-errCh:
+ assert.NoError(t, e.Error)
+ assert.NoError(t, container.Stop())
+ return
+ case <-c:
+ err = container.Stop()
+ assert.NoError(t, err)
+ return
+ case <-stopCh:
+ assert.NoError(t, container.Stop())
+ return
+ }
+ }
+ }()
+
+ time.Sleep(time.Second * 2)
+
+ f, err := os.ReadFile("test.log")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ assert.Contains(t, string(f), "Example marshaller error")
+ assert.Equal(t, 4, strings.Count(string(f), "Example marshaller error"))
+
+ _ = os.Remove("test.log")
+
+ stopCh <- struct{}{}
+ wg.Wait()
+}
diff --git a/tests/plugins/logger/plugin.go b/tests/plugins/logger/plugin.go
index e2227ec9..54e78d7b 100644
--- a/tests/plugins/logger/plugin.go
+++ b/tests/plugins/logger/plugin.go
@@ -43,7 +43,7 @@ func (p1 *Plugin) Serve() chan error {
p1.log.Debug("error", field)
p1.log.Warn("error", field)
- marshalledObject := Loggable{}
+ marshalledObject := &Loggable{}
p1.log.Error("error", marshalledObject)
p1.log.Info("error", marshalledObject)