Skip to content

Commit cd086ac

Browse files
authored
Merge pull request #24 from gnolang/feat/use-slog
feat: utilize slog
2 parents 5fbbc33 + 28379aa commit cd086ac

File tree

10 files changed

+16
-87
lines changed

10 files changed

+16
-87
lines changed

cmd/logger.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

cmd/serve.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8+
"log/slog"
89
"os"
910
"regexp"
1011
"strconv"
@@ -18,7 +19,6 @@ import (
1819
"github.com/peterbourgon/ff/v3"
1920
"github.com/peterbourgon/ff/v3/ffcli"
2021
"github.com/peterbourgon/ff/v3/fftoml"
21-
"go.uber.org/zap"
2222
)
2323

2424
const (
@@ -179,17 +179,14 @@ func (c *faucetCfg) exec(_ context.Context, _ []string) error {
179179
}
180180

181181
// Create a new logger
182-
logger, err := zap.NewDevelopment()
183-
if err != nil {
184-
return err
185-
}
182+
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
186183

187184
// Create a new faucet with
188185
// static gas estimation
189186
f, err := faucet.NewFaucet(
190187
static.New(gasFee, gasWanted),
191188
tm2Client.NewClient(c.remote),
192-
faucet.WithLogger(newCommandLogger(logger)),
189+
faucet.WithLogger(logger),
193190
faucet.WithConfig(c.config),
194191
)
195192
if err != nil {

faucet.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"io"
8+
"log/slog"
79
"net"
810
"net/http"
911
"time"
@@ -13,8 +15,6 @@ import (
1315
"github.com/gnolang/faucet/estimate"
1416
"github.com/gnolang/faucet/keyring"
1517
"github.com/gnolang/faucet/keyring/memory"
16-
"github.com/gnolang/faucet/log"
17-
"github.com/gnolang/faucet/log/noop"
1818
"github.com/gnolang/gno/tm2/pkg/std"
1919
"github.com/go-chi/chi/v5"
2020
"github.com/rs/cors"
@@ -24,7 +24,7 @@ import (
2424
// Faucet is a standard Gno faucet
2525
type Faucet struct {
2626
estimator estimate.Estimator // gas pricing estimations
27-
logger log.Logger // log feedback
27+
logger *slog.Logger // log feedback
2828
client client.Client // TM2 client
2929
keyring keyring.Keyring // the faucet keyring
3030

@@ -38,6 +38,8 @@ type Faucet struct {
3838
sendAmount std.Coins // for fast lookup
3939
}
4040

41+
var noopLogger = slog.New(slog.NewTextHandler(io.Discard, nil))
42+
4143
// NewFaucet creates a new instance of the Gno faucet server
4244
func NewFaucet(
4345
estimator estimate.Estimator,
@@ -47,7 +49,7 @@ func NewFaucet(
4749
f := &Faucet{
4850
estimator: estimator,
4951
client: client,
50-
logger: noop.New(),
52+
logger: noopLogger,
5153
config: config.DefaultConfig(),
5254
prepareTxMsgFn: defaultPrepareTxMessage,
5355
middlewares: nil, // no middlewares by default

faucet_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/gnolang/faucet/config"
8-
"github.com/gnolang/faucet/log/noop"
98
"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
109
"github.com/gnolang/gno/tm2/pkg/crypto"
1110
"github.com/gnolang/gno/tm2/pkg/std"
@@ -135,7 +134,7 @@ func TestFaucet_NewFaucet(t *testing.T) {
135134
&mockEstimator{},
136135
&mockClient{},
137136
WithConfig(config.DefaultConfig()),
138-
WithLogger(noop.New()),
137+
WithLogger(noopLogger),
139138
)
140139

141140
assert.NotNil(t, f)

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/peterbourgon/ff/v3 v3.4.0
1010
github.com/rs/cors v1.10.1
1111
github.com/stretchr/testify v1.9.0
12-
go.uber.org/zap v1.27.0
1312
golang.org/x/sync v0.6.0
1413
)
1514

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,8 @@ go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
158158
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
159159
go.opencensus.io v0.22.5 h1:dntmOdLpSpHlVqbW5Eay97DelsZHe+55D+xC6i0dDS0=
160160
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
161-
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
162-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
163161
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
164162
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
165-
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
166-
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
167163
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
168164
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
169165
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

log/log.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

log/noop/noop.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package faucet
22

33
import (
4+
"log/slog"
5+
46
"github.com/gnolang/faucet/config"
5-
"github.com/gnolang/faucet/log"
67
)
78

89
type Option func(f *Faucet)
910

1011
// WithLogger specifies the logger for the faucet
11-
func WithLogger(l log.Logger) Option {
12+
func WithLogger(l *slog.Logger) Option {
1213
return func(f *Faucet) {
1314
f.logger = l
1415
}

writer/http/http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ package http
33
import (
44
"encoding/json"
55
"fmt"
6+
"log/slog"
67
"net/http"
78

8-
"github.com/gnolang/faucet/log"
99
"github.com/gnolang/faucet/writer"
1010
)
1111

1212
var _ writer.ResponseWriter = (*ResponseWriter)(nil)
1313

1414
type ResponseWriter struct {
15-
logger log.Logger
15+
logger *slog.Logger
1616
w http.ResponseWriter
1717
}
1818

19-
func New(logger log.Logger, w http.ResponseWriter) ResponseWriter {
19+
func New(logger *slog.Logger, w http.ResponseWriter) ResponseWriter {
2020
return ResponseWriter{
2121
logger: logger,
2222
w: w,

0 commit comments

Comments
 (0)