From 91a1ee956ca527426cc86422fa64ff7b30fd79b3 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Sun, 14 Mar 2021 21:51:14 +0300 Subject: [PATCH] Add noop logger --- logger/noop.go | 19 +++++++++++++++++++ logger/noop_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 logger/noop.go create mode 100644 logger/noop_test.go diff --git a/logger/noop.go b/logger/noop.go new file mode 100644 index 0000000..6d7289c --- /dev/null +++ b/logger/noop.go @@ -0,0 +1,19 @@ +package logger + +import "github.com/9seconds/mtg/v2/mtglib" + +type noopLogger struct{} + +func (n noopLogger) Named(_ string) mtglib.Logger { return n } +func (n noopLogger) BindInt(_ string, _ int) mtglib.Logger { return n } +func (n noopLogger) BindStr(_, _ string) mtglib.Logger { return n } +func (n noopLogger) Info(_ string) {} +func (n noopLogger) Warning(_ string) {} +func (n noopLogger) Debug(_ string) {} +func (n noopLogger) InfoError(_ string, _ error) {} +func (n noopLogger) WarningError(_ string, _ error) {} +func (n noopLogger) DebugError(_ string, _ error) {} + +func NewNoopLogger() mtglib.Logger { + return noopLogger{} +} diff --git a/logger/noop_test.go b/logger/noop_test.go new file mode 100644 index 0000000..add8464 --- /dev/null +++ b/logger/noop_test.go @@ -0,0 +1,34 @@ +package logger_test + +import ( + "io" + "testing" + + "github.com/9seconds/mtg/v2/logger" + "github.com/9seconds/mtg/v2/testlib" + "github.com/stretchr/testify/suite" +) + +type NoopLoggerTestSuite struct { + suite.Suite +} + +func (suite *NoopLoggerTestSuite) TestLog() { + suite.Empty(testlib.CaptureStdout(func() { + suite.Empty(testlib.CaptureStderr(func() { + log := logger.NewNoopLogger().Named("name") + + log.BindInt("int", 1).BindStr("str", "1").Info("info") + log.BindInt("int", 1).BindStr("str", "1").Warning("info") + log.BindInt("int", 1).BindStr("str", "1").Debug("info") + log.BindInt("int", 1).BindStr("str", "1").InfoError("info", io.EOF) + log.BindInt("int", 1).BindStr("str", "1").WarningError("info", io.EOF) + log.BindInt("int", 1).BindStr("str", "1").DebugError("info", io.EOF) + })) + })) +} + +func TestNoopLogger(t *testing.T) { + t.Parallel() + suite.Run(t, &NoopLoggerTestSuite{}) +}