Skip to content

Commit

Permalink
Utilize slog
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Mar 7, 2024
1 parent 5fbbc33 commit f36f1b1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 62 deletions.
43 changes: 0 additions & 43 deletions cmd/logger.go

This file was deleted.

9 changes: 3 additions & 6 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"flag"
"fmt"
"log/slog"
"os"
"regexp"
"strconv"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"io"
"log/slog"
"net"
"net/http"
"time"
Expand All @@ -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"
Expand All @@ -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

Expand All @@ -47,7 +47,7 @@ func NewFaucet(
f := &Faucet{
estimator: estimator,
client: client,
logger: noop.New(),
logger: slog.New(slog.NewTextHandler(io.Discard, nil)),
config: config.DefaultConfig(),
prepareTxMsgFn: defaultPrepareTxMessage,
middlewares: nil, // no middlewares by default
Expand Down
5 changes: 3 additions & 2 deletions faucet_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package faucet

import (
"io"
"log/slog"
"net/http"
"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"
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestFaucet_NewFaucet(t *testing.T) {
&mockEstimator{},
&mockClient{},
WithConfig(config.DefaultConfig()),
WithLogger(noop.New()),
WithLogger(slog.New(slog.NewTextHandler(io.Discard, nil))),
)

assert.NotNil(t, f)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 3 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down

0 comments on commit f36f1b1

Please sign in to comment.