diff options
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | plugins/logger/config.go | 2 | ||||
-rw-r--r-- | tests/plugins/logger/configs/.rr-raw-mode.yaml | 2 | ||||
-rw-r--r-- | tests/plugins/logger/logger_test.go | 65 | ||||
-rw-r--r-- | tests/plugins/logger/plugin.go | 7 |
6 files changed, 78 insertions, 1 deletions
@@ -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 @@ -220,6 +220,8 @@ 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/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 284ab6ea..bfe45f78 100644 --- a/plugins/logger/config.go +++ b/plugins/logger/config.go @@ -50,7 +50,7 @@ func (cfg *Config) BuildLogger() (*zap.Logger, error) { zCfg = zap.NewProductionConfig() case "development": zCfg = zap.NewDevelopmentConfig() - case "clean": + case "raw": zCfg = zap.Config{ Level: zap.NewAtomicLevelAt(zap.DebugLevel), Encoding: "console", 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..38da7266 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 } |