diff --git a/cmd/logger.go b/cmd/logger.go deleted file mode 100644 index c09a5d1..0000000 --- a/cmd/logger.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import "go.uber.org/zap" - -type cmdLogger struct { - logger *zap.Logger -} - -func newCommandLogger(logger *zap.Logger) *cmdLogger { - return &cmdLogger{ - logger: logger, - } -} - -func (c *cmdLogger) Info(msg string, args ...interface{}) { - if len(args) == 0 { - c.logger.Info(msg) - - return - } - - c.logger.Info(msg, zap.Any("args", args)) -} - -func (c *cmdLogger) Debug(msg string, args ...interface{}) { - if len(args) == 0 { - c.logger.Debug(msg) - - return - } - - c.logger.Debug(msg, zap.Any("args", args)) -} - -func (c *cmdLogger) Error(msg string, args ...interface{}) { - if len(args) == 0 { - c.logger.Error(msg) - - return - } - - c.logger.Error(msg, zap.Any("args", args)) -} diff --git a/cmd/serve.go b/cmd/serve.go index 471f86c..27afed4 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -5,6 +5,7 @@ import ( "errors" "flag" "fmt" + "log/slog" "os" "regexp" "strconv" @@ -18,7 +19,6 @@ import ( "github.com/peterbourgon/ff/v3" "github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/fftoml" - "go.uber.org/zap" ) const ( @@ -179,17 +179,14 @@ func (c *faucetCfg) exec(_ context.Context, _ []string) error { } // Create a new logger - logger, err := zap.NewDevelopment() - if err != nil { - return err - } + logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) // Create a new faucet with // static gas estimation f, err := faucet.NewFaucet( static.New(gasFee, gasWanted), tm2Client.NewClient(c.remote), - faucet.WithLogger(newCommandLogger(logger)), + faucet.WithLogger(logger), faucet.WithConfig(c.config), ) if err != nil { diff --git a/faucet.go b/faucet.go index 8b74ecf..8873704 100644 --- a/faucet.go +++ b/faucet.go @@ -4,6 +4,8 @@ import ( "context" "errors" "fmt" + "io" + "log/slog" "net" "net/http" "time" @@ -13,8 +15,6 @@ import ( "github.com/gnolang/faucet/estimate" "github.com/gnolang/faucet/keyring" "github.com/gnolang/faucet/keyring/memory" - "github.com/gnolang/faucet/log" - "github.com/gnolang/faucet/log/noop" "github.com/gnolang/gno/tm2/pkg/std" "github.com/go-chi/chi/v5" "github.com/rs/cors" @@ -24,7 +24,7 @@ import ( // Faucet is a standard Gno faucet type Faucet struct { estimator estimate.Estimator // gas pricing estimations - logger log.Logger // log feedback + logger *slog.Logger // log feedback client client.Client // TM2 client keyring keyring.Keyring // the faucet keyring @@ -38,6 +38,8 @@ type Faucet struct { sendAmount std.Coins // for fast lookup } +var noopLogger = slog.New(slog.NewTextHandler(io.Discard, nil)) + // NewFaucet creates a new instance of the Gno faucet server func NewFaucet( estimator estimate.Estimator, @@ -47,7 +49,7 @@ func NewFaucet( f := &Faucet{ estimator: estimator, client: client, - logger: noop.New(), + logger: noopLogger, config: config.DefaultConfig(), prepareTxMsgFn: defaultPrepareTxMessage, middlewares: nil, // no middlewares by default diff --git a/faucet_test.go b/faucet_test.go index 6e17d3a..a17db71 100644 --- a/faucet_test.go +++ b/faucet_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/gnolang/faucet/config" - "github.com/gnolang/faucet/log/noop" "github.com/gnolang/gno/gno.land/pkg/sdk/vm" "github.com/gnolang/gno/tm2/pkg/crypto" "github.com/gnolang/gno/tm2/pkg/std" @@ -135,7 +134,7 @@ func TestFaucet_NewFaucet(t *testing.T) { &mockEstimator{}, &mockClient{}, WithConfig(config.DefaultConfig()), - WithLogger(noop.New()), + WithLogger(noopLogger), ) assert.NotNil(t, f) diff --git a/go.mod b/go.mod index ad26858..fe65475 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/peterbourgon/ff/v3 v3.4.0 github.com/rs/cors v1.10.1 github.com/stretchr/testify v1.9.0 - go.uber.org/zap v1.27.0 golang.org/x/sync v0.6.0 ) diff --git a/go.sum b/go.sum index c79ec1f..7895b87 100644 --- a/go.sum +++ b/go.sum @@ -158,12 +158,8 @@ go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/log/log.go b/log/log.go deleted file mode 100644 index b2703ff..0000000 --- a/log/log.go +++ /dev/null @@ -1,7 +0,0 @@ -package log - -type Logger interface { - Info(msg string, args ...interface{}) - Debug(msg string, args ...interface{}) - Error(msg string, args ...interface{}) -} diff --git a/log/noop/noop.go b/log/noop/noop.go deleted file mode 100644 index 6e11d39..0000000 --- a/log/noop/noop.go +++ /dev/null @@ -1,15 +0,0 @@ -package noop - -// Logger is the nil (noop) logger -type Logger struct{} - -// New creates a nil logger -func New() *Logger { - return &Logger{} -} - -func (l Logger) Info(_ string, _ ...interface{}) {} - -func (l Logger) Debug(_ string, _ ...interface{}) {} - -func (l Logger) Error(_ string, _ ...interface{}) {} diff --git a/options.go b/options.go index c721150..c58de87 100644 --- a/options.go +++ b/options.go @@ -1,14 +1,15 @@ package faucet import ( + "log/slog" + "github.com/gnolang/faucet/config" - "github.com/gnolang/faucet/log" ) type Option func(f *Faucet) // WithLogger specifies the logger for the faucet -func WithLogger(l log.Logger) Option { +func WithLogger(l *slog.Logger) Option { return func(f *Faucet) { f.logger = l } diff --git a/writer/http/http.go b/writer/http/http.go index 765c205..5265e4e 100644 --- a/writer/http/http.go +++ b/writer/http/http.go @@ -3,20 +3,20 @@ package http import ( "encoding/json" "fmt" + "log/slog" "net/http" - "github.com/gnolang/faucet/log" "github.com/gnolang/faucet/writer" ) var _ writer.ResponseWriter = (*ResponseWriter)(nil) type ResponseWriter struct { - logger log.Logger + logger *slog.Logger w http.ResponseWriter } -func New(logger log.Logger, w http.ResponseWriter) ResponseWriter { +func New(logger *slog.Logger, w http.ResponseWriter) ResponseWriter { return ResponseWriter{ logger: logger, w: w,