Skip to content

Commit 1810ce0

Browse files
cmd/nsqlookup-proxy: replace log use of segmentio/events
1 parent 2867d16 commit 1810ce0

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

cmd/nsqlookup-proxy/main.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package main
22

33
import (
4+
"log/slog"
45
"net"
56
"net/http"
67
"os"
78
"strings"
89
"time"
910

1011
"github.com/segmentio/conf"
11-
"github.com/segmentio/events"
12-
_ "github.com/segmentio/events/ecslogs"
13-
"github.com/segmentio/events/httpevents"
14-
_ "github.com/segmentio/events/text"
12+
"github.com/segmentio/events/v2/httpevents"
1513
nsq "github.com/segmentio/nsq-go"
1614
"github.com/segmentio/nsq-go/nsqlookup"
1715
)
@@ -35,8 +33,12 @@ func main() {
3533
}
3634

3735
args := conf.Load(&config)
38-
events.DefaultLogger.EnableDebug = config.Debug
39-
events.DefaultLogger.EnableSource = config.Debug
36+
if config.Debug {
37+
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
38+
Level: slog.LevelDebug,
39+
AddSource: true,
40+
})))
41+
}
4042

4143
var transport http.RoundTripper = http.DefaultTransport
4244
if config.Verbose {
@@ -46,10 +48,10 @@ func main() {
4648
switch len(args) {
4749
case 1:
4850
case 0:
49-
events.Log("missing registry endpoint")
51+
slog.Info("missing registry endpoint")
5052
os.Exit(1)
5153
default:
52-
events.Log("too many registry endpoints: %{endpoints}v", args)
54+
slog.Info("too many registry endpoints", "endponts", args)
5355
os.Exit(1)
5456
}
5557

@@ -58,37 +60,37 @@ func main() {
5860

5961
switch protocol {
6062
case "consul":
61-
events.Log("using consul registry at %{address}s", address)
63+
slog.Info("using consul registry", "address", address)
6264
registry = &nsqlookup.ConsulRegistry{
6365
Address: address,
6466
Transport: transport,
6567
}
6668
case "":
67-
events.Log("using local registry mapping %{service}s to %{address}s", nsqlookupd, address)
69+
slog.Info("using local registry mapping", "service", nsqlookupd, "address", address)
6870
registry = nsqlookup.LocalRegistry{
6971
nsqlookupd: {address},
7072
}
7173
default:
72-
events.Log("unknown registry: %{protocol}s://%{address}s", protocol, address)
74+
slog.Error("unknown registry", "protocol", protocol, "address", address)
7375
os.Exit(1)
7476
}
7577

7678
var topology nsqlookup.SubnetTopology
7779
for subnet, zone := range config.Topology {
7880
_, cidr, err := net.ParseCIDR(subnet)
7981
if err != nil {
80-
events.Log("error parsing %{subnet}s subnet: %{error}v", subnet, err)
82+
slog.Warn("error parsing subnet", "subnet", subnet, "err", err)
8183
continue
8284
}
8385
topology = append(topology, nsqlookup.Subnet{
8486
CIDR: cidr,
8587
Zone: zone,
8688
})
87-
events.Log("configuring network topology with %{cidr}s subnet in zone %{zone}s", cidr, zone)
89+
slog.Info("configuring network topology with specified subnet", "cidr", cidr, "zone", zone)
8890
}
8991

9092
for _, topic := range config.ZoneAwareTopics {
91-
events.Log("applying zone restriction to topic %{topic}s", topic)
93+
slog.Info("applying zone restriction to topic", "topic", topic)
9294
}
9395

9496
var proxy = &nsqlookup.ProxyEngine{
@@ -114,7 +116,7 @@ func main() {
114116
handler = httpevents.NewHandler(handler)
115117
}
116118

117-
events.Log("starting nsqlookup-proxy listening on %{address}s", config.Bind)
119+
slog.Info("starting nsqlookup-proxy", "listen_address", config.Bind)
118120
http.ListenAndServe(config.Bind, handler)
119121
}
120122

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module github.com/segmentio/nsq-go
33
go 1.11
44

55
require (
6-
github.com/pkg/errors v0.8.0
6+
github.com/pkg/errors v0.9.1
77
github.com/segmentio/conf v1.0.0
8-
github.com/segmentio/events v2.1.0+incompatible
8+
github.com/segmentio/events/v2 v2.6.0
99
github.com/segmentio/go-snakecase v1.0.0 // indirect
1010
github.com/segmentio/objconv v1.0.1 // indirect
1111
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e
12+
golang.org/x/sys v0.15.0 // indirect
1213
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
1314
gopkg.in/go-playground/mold.v2 v2.2.0 // indirect
1415
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 // indirect

go.sum

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
2-
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3+
github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg=
34
github.com/segmentio/conf v1.0.0 h1:oRF4BtoJbI/+I7fUngYMnMcKFbjqVUFi8hv4Pp0l88w=
45
github.com/segmentio/conf v1.0.0/go.mod h1:y0VyxYAlU2slxCjm7XX7tGKFlN39bwHCZrbOpCcLsr8=
5-
github.com/segmentio/events v2.1.0+incompatible h1:7ns47dgRJMt/JgIXrNU0MiD/NtCGa55lKzWP15dcGnM=
6-
github.com/segmentio/events v2.1.0+incompatible/go.mod h1:npQUbmKYO33tlRpaQNZjgD2mXv0fb2hbOH0CNVs6g2Y=
6+
github.com/segmentio/encoding v0.3.6/go.mod h1:n0JeuIqEQrQoPDGsjo8UNd1iA0U8d8+oHAA4E3G3OxM=
7+
github.com/segmentio/events/v2 v2.6.0 h1:MRPhHWwfLGFjkppjkdCDw2DZVBMyMb/JcBVnDVVNdzc=
8+
github.com/segmentio/events/v2 v2.6.0/go.mod h1:oDngvacuvZ/bPnAq8VKNzvk8ICS1pVVEtQESVcvSL/w=
79
github.com/segmentio/go-snakecase v1.0.0 h1:FSeHpP0sBL3O+MCpxvQZrS5a51WAki6gposZuwVE9L4=
810
github.com/segmentio/go-snakecase v1.0.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto=
911
github.com/segmentio/objconv v1.0.1 h1:QjfLzwriJj40JibCV3MGSEiAoXixbp4ybhwfTB8RXOM=
1012
github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys=
1113
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e h1:GNlZqttb0RQTUYTYnSwAMyqgHzYouBGVImRJp8Y43Hg=
1214
github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e/go.mod h1:/6SKE4F6LzTh32hPOJs0KRJ7MHHWpTZ7wb4PxdjgzaQ=
15+
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
17+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
18+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1319
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1420
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1521
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=

0 commit comments

Comments
 (0)