summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--go.mod1
-rw-r--r--go.sum2
-rw-r--r--plugins/logger/config.go10
-rw-r--r--tests/plugins/logger/configs/.rr-raw-mode.yaml2
-rw-r--r--tests/plugins/logger/logger_test.go65
-rw-r--r--tests/plugins/logger/plugin.go7
7 files changed, 88 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d652e1d8..b32ce421 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ v2.0.3 (29.03.2021)
## 🩹 Fixes:
- 🐛 Fix: slow last response when reached `max_jobs` limit.
+- 📜 Add a new `raw` mode for the `logger` plugin to keep the stderr log message of the worker unmodified.
v2.0.2 (06.04.2021)
-------------------
diff --git a/go.mod b/go.mod
index 3af5554d..52e8c899 100644
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
github.com/golang/mock v1.4.4
github.com/hashicorp/go-multierror v1.1.1
github.com/json-iterator/go v1.1.10
+ github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.10.0
github.com/shirou/gopsutil v3.21.2+incompatible
diff --git a/go.sum b/go.sum
index 01c82b42..8b394b15 100644
--- a/go.sum
+++ b/go.sum
@@ -322,6 +322,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
+github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d h1:cVtBfNW5XTHiKQe7jDaDBSh/EVM4XLPutLAGboIXuM0=
+github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0=
github.com/kisielk/errcheck v1.1.0 h1:ZqfnKyx9KGpRcW04j5nnPDgRgoXUeLh2YFBeFzphcA0=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
diff --git a/plugins/logger/config.go b/plugins/logger/config.go
index 52594bc4..bfe45f78 100644
--- a/plugins/logger/config.go
+++ b/plugins/logger/config.go
@@ -50,6 +50,16 @@ func (cfg *Config) BuildLogger() (*zap.Logger, error) {
zCfg = zap.NewProductionConfig()
case "development":
zCfg = zap.NewDevelopmentConfig()
+ case "raw":
+ zCfg = zap.Config{
+ Level: zap.NewAtomicLevelAt(zap.DebugLevel),
+ Encoding: "console",
+ EncoderConfig: zapcore.EncoderConfig{
+ MessageKey: "message",
+ },
+ OutputPaths: []string{"stderr"},
+ ErrorOutputPaths: []string{"stderr"},
+ }
default:
zCfg = zap.Config{
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
diff --git a/tests/plugins/logger/configs/.rr-raw-mode.yaml b/tests/plugins/logger/configs/.rr-raw-mode.yaml
new file mode 100644
index 00000000..77bd2f59
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-raw-mode.yaml
@@ -0,0 +1,2 @@
+logs:
+ mode: raw \ No newline at end of file
diff --git a/tests/plugins/logger/logger_test.go b/tests/plugins/logger/logger_test.go
index 7f378026..a1bc0f4d 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -6,6 +6,8 @@ import (
"sync"
"testing"
+ "github.com/kami-zh/go-capturer"
+
endure "github.com/spiral/endure/pkg/container"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/http"
@@ -74,6 +76,69 @@ func TestLogger(t *testing.T) {
wg.Wait()
}
+func TestLoggerRawMode(t *testing.T) {
+ out := capturer.CaptureOutput(func() {
+ 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-raw-mode.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
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+ })
+
+ assert.Contains(t, out, `{"field": "value"}`)
+}
+
func TestLoggerNoConfig(t *testing.T) {
container, err := endure.NewContainer(nil, endure.RetryOnFail(true), endure.SetLogLevel(endure.ErrorLevel))
if err != nil {
diff --git a/tests/plugins/logger/plugin.go b/tests/plugins/logger/plugin.go
index 9ddf9ec9..aa62f2b3 100644
--- a/tests/plugins/logger/plugin.go
+++ b/tests/plugins/logger/plugin.go
@@ -1,6 +1,8 @@
package logger
import (
+ "strings"
+
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/logger"
@@ -28,6 +30,11 @@ func (p1 *Plugin) Serve() chan error {
p1.log.Info("error", "test")
p1.log.Debug("error", "test")
p1.log.Warn("error", "test")
+
+ // test the `raw` mode
+ messageJSON := []byte(`{"field": "value"}`)
+ p1.log.Debug(strings.TrimRight(string(messageJSON), " \n\t"))
+
return errCh
}