Przeglądaj źródła

Add noop logger

tags/v2.0.0-rc1
9seconds 5 lat temu
rodzic
commit
91a1ee956c
2 zmienionych plików z 53 dodań i 0 usunięć
  1. 19
    0
      logger/noop.go
  2. 34
    0
      logger/noop_test.go

+ 19
- 0
logger/noop.go Wyświetl plik

@@ -0,0 +1,19 @@
1
+package logger
2
+
3
+import "github.com/9seconds/mtg/v2/mtglib"
4
+
5
+type noopLogger struct{}
6
+
7
+func (n noopLogger) Named(_ string) mtglib.Logger          { return n }
8
+func (n noopLogger) BindInt(_ string, _ int) mtglib.Logger { return n }
9
+func (n noopLogger) BindStr(_, _ string) mtglib.Logger     { return n }
10
+func (n noopLogger) Info(_ string)                         {}
11
+func (n noopLogger) Warning(_ string)                      {}
12
+func (n noopLogger) Debug(_ string)                        {}
13
+func (n noopLogger) InfoError(_ string, _ error)           {}
14
+func (n noopLogger) WarningError(_ string, _ error)        {}
15
+func (n noopLogger) DebugError(_ string, _ error)          {}
16
+
17
+func NewNoopLogger() mtglib.Logger {
18
+	return noopLogger{}
19
+}

+ 34
- 0
logger/noop_test.go Wyświetl plik

@@ -0,0 +1,34 @@
1
+package logger_test
2
+
3
+import (
4
+	"io"
5
+	"testing"
6
+
7
+	"github.com/9seconds/mtg/v2/logger"
8
+	"github.com/9seconds/mtg/v2/testlib"
9
+	"github.com/stretchr/testify/suite"
10
+)
11
+
12
+type NoopLoggerTestSuite struct {
13
+	suite.Suite
14
+}
15
+
16
+func (suite *NoopLoggerTestSuite) TestLog() {
17
+	suite.Empty(testlib.CaptureStdout(func() {
18
+		suite.Empty(testlib.CaptureStderr(func() {
19
+			log := logger.NewNoopLogger().Named("name")
20
+
21
+			log.BindInt("int", 1).BindStr("str", "1").Info("info")
22
+			log.BindInt("int", 1).BindStr("str", "1").Warning("info")
23
+			log.BindInt("int", 1).BindStr("str", "1").Debug("info")
24
+			log.BindInt("int", 1).BindStr("str", "1").InfoError("info", io.EOF)
25
+			log.BindInt("int", 1).BindStr("str", "1").WarningError("info", io.EOF)
26
+			log.BindInt("int", 1).BindStr("str", "1").DebugError("info", io.EOF)
27
+		}))
28
+	}))
29
+}
30
+
31
+func TestNoopLogger(t *testing.T) {
32
+	t.Parallel()
33
+	suite.Run(t, &NoopLoggerTestSuite{})
34
+}

Ładowanie…
Anuluj
Zapisz