summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--go.mod1
-rw-r--r--go.sum3
-rw-r--r--plugins/logger/config.go10
-rw-r--r--tests/plugins/logger/configs/.rr-raw-mode.yaml15
-rw-r--r--tests/plugins/logger/logger_test.go71
-rw-r--r--tests/plugins/logger/plugin.go7
-rw-r--r--tests/raw-error.php30
8 files changed, 138 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 1a5263fb..0e6c7079 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.3+incompatible
diff --git a/go.sum b/go.sum
index a015f236..e6d7df35 100644
--- a/go.sum
+++ b/go.sum
@@ -220,6 +220,9 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
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/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
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..0e62ab95
--- /dev/null
+++ b/tests/plugins/logger/configs/.rr-raw-mode.yaml
@@ -0,0 +1,15 @@
+server:
+ command: "php ../../raw-error.php"
+ relay: "pipes"
+
+http:
+ address: 127.0.0.1:34999
+ maxRequestSize: 1024
+ pool:
+ numWorkers: 1
+ maxJobs: 0
+ allocateTimeout: 10s
+ destroyTimeout: 10s
+
+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..f212cc8a 100644
--- a/tests/plugins/logger/logger_test.go
+++ b/tests/plugins/logger/logger_test.go
@@ -4,8 +4,11 @@ import (
"os"
"os/signal"
"sync"
+ "syscall"
"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 +77,74 @@ func TestLogger(t *testing.T) {
wg.Wait()
}
+func TestLoggerRawErr(t *testing.T) {
+ out := capturer.CaptureOutput(func() {
+ cont, err := endure.NewContainer(nil, endure.SetLogLevel(endure.ErrorLevel))
+ assert.NoError(t, err)
+
+ // config plugin
+ cfg := &config.Viper{}
+ cfg.Path = "configs/.rr-raw-mode.yaml"
+ cfg.Prefix = "rr"
+
+ err = cont.RegisterAll(
+ cfg,
+ &logger.ZapLogger{},
+ &server.Plugin{},
+ &http.Plugin{},
+ )
+ assert.NoError(t, err)
+
+ err = cont.Init()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ch, err := cont.Serve()
+ assert.NoError(t, err)
+
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ stopCh := make(chan struct{}, 1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case e := <-ch:
+ assert.Fail(t, "error", e.Error.Error())
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ case <-sig:
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ case <-stopCh:
+ // timeout
+ err = cont.Stop()
+ if err != nil {
+ assert.FailNow(t, "error", err.Error())
+ }
+ return
+ }
+ }
+ }()
+
+ stopCh <- struct{}{}
+ wg.Wait()
+ })
+
+ assert.Contains(t, out, "\n{\"field\": \"value\"}\n")
+}
+
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
}
diff --git a/tests/raw-error.php b/tests/raw-error.php
new file mode 100644
index 00000000..e8ca328b
--- /dev/null
+++ b/tests/raw-error.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * @var Goridge\RelayInterface $relay
+ */
+use Spiral\Goridge;
+use Spiral\RoadRunner;
+
+ini_set('display_errors', 'stderr');
+require __DIR__ . "/vendor/autoload.php";
+
+$worker = new RoadRunner\Worker(new Goridge\StreamRelay(STDIN, STDOUT));
+$psr7 = new RoadRunner\Http\PSR7Worker(
+ $worker,
+ new \Nyholm\Psr7\Factory\Psr17Factory(),
+ new \Nyholm\Psr7\Factory\Psr17Factory(),
+ new \Nyholm\Psr7\Factory\Psr17Factory()
+);
+
+error_log('{"field": "value"}');
+
+while ($req = $psr7->waitRequest()) {
+ try {
+ $resp = new \Nyholm\Psr7\Response();
+ $resp->getBody()->write("hello world");
+
+ $psr7->respond($resp);
+ } catch (\Throwable $e) {
+ $psr7->getWorker()->error((string)$e);
+ }
+} \ No newline at end of file