From 1810ce0c3756c9e7bdecc557edcb1df6f1a28faf Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 7 Dec 2023 16:40:48 -0800 Subject: [PATCH] cmd/nsqlookup-proxy: replace log use of segmentio/events --- cmd/nsqlookup-proxy/main.go | 32 +++++++++++++++++--------------- go.mod | 5 +++-- go.sum | 14 ++++++++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/cmd/nsqlookup-proxy/main.go b/cmd/nsqlookup-proxy/main.go index 1ba52fb..8ebce2e 100644 --- a/cmd/nsqlookup-proxy/main.go +++ b/cmd/nsqlookup-proxy/main.go @@ -1,6 +1,7 @@ package main import ( + "log/slog" "net" "net/http" "os" @@ -8,10 +9,7 @@ import ( "time" "github.com/segmentio/conf" - "github.com/segmentio/events" - _ "github.com/segmentio/events/ecslogs" - "github.com/segmentio/events/httpevents" - _ "github.com/segmentio/events/text" + "github.com/segmentio/events/v2/httpevents" nsq "github.com/segmentio/nsq-go" "github.com/segmentio/nsq-go/nsqlookup" ) @@ -35,8 +33,12 @@ func main() { } args := conf.Load(&config) - events.DefaultLogger.EnableDebug = config.Debug - events.DefaultLogger.EnableSource = config.Debug + if config.Debug { + slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{ + Level: slog.LevelDebug, + AddSource: true, + }))) + } var transport http.RoundTripper = http.DefaultTransport if config.Verbose { @@ -46,10 +48,10 @@ func main() { switch len(args) { case 1: case 0: - events.Log("missing registry endpoint") + slog.Info("missing registry endpoint") os.Exit(1) default: - events.Log("too many registry endpoints: %{endpoints}v", args) + slog.Info("too many registry endpoints", "endponts", args) os.Exit(1) } @@ -58,18 +60,18 @@ func main() { switch protocol { case "consul": - events.Log("using consul registry at %{address}s", address) + slog.Info("using consul registry", "address", address) registry = &nsqlookup.ConsulRegistry{ Address: address, Transport: transport, } case "": - events.Log("using local registry mapping %{service}s to %{address}s", nsqlookupd, address) + slog.Info("using local registry mapping", "service", nsqlookupd, "address", address) registry = nsqlookup.LocalRegistry{ nsqlookupd: {address}, } default: - events.Log("unknown registry: %{protocol}s://%{address}s", protocol, address) + slog.Error("unknown registry", "protocol", protocol, "address", address) os.Exit(1) } @@ -77,18 +79,18 @@ func main() { for subnet, zone := range config.Topology { _, cidr, err := net.ParseCIDR(subnet) if err != nil { - events.Log("error parsing %{subnet}s subnet: %{error}v", subnet, err) + slog.Warn("error parsing subnet", "subnet", subnet, "err", err) continue } topology = append(topology, nsqlookup.Subnet{ CIDR: cidr, Zone: zone, }) - events.Log("configuring network topology with %{cidr}s subnet in zone %{zone}s", cidr, zone) + slog.Info("configuring network topology with specified subnet", "cidr", cidr, "zone", zone) } for _, topic := range config.ZoneAwareTopics { - events.Log("applying zone restriction to topic %{topic}s", topic) + slog.Info("applying zone restriction to topic", "topic", topic) } var proxy = &nsqlookup.ProxyEngine{ @@ -114,7 +116,7 @@ func main() { handler = httpevents.NewHandler(handler) } - events.Log("starting nsqlookup-proxy listening on %{address}s", config.Bind) + slog.Info("starting nsqlookup-proxy", "listen_address", config.Bind) http.ListenAndServe(config.Bind, handler) } diff --git a/go.mod b/go.mod index 8478bd9..b21bdc5 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,13 @@ module github.com/segmentio/nsq-go go 1.11 require ( - github.com/pkg/errors v0.8.0 + github.com/pkg/errors v0.9.1 github.com/segmentio/conf v1.0.0 - github.com/segmentio/events v2.1.0+incompatible + github.com/segmentio/events/v2 v2.6.0 github.com/segmentio/go-snakecase v1.0.0 // indirect github.com/segmentio/objconv v1.0.1 // indirect github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e + golang.org/x/sys v0.15.0 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/mold.v2 v2.2.0 // indirect gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 // indirect diff --git a/go.sum b/go.sum index 7ad3332..b111690 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,21 @@ -github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/segmentio/asm v1.1.3/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg= github.com/segmentio/conf v1.0.0 h1:oRF4BtoJbI/+I7fUngYMnMcKFbjqVUFi8hv4Pp0l88w= github.com/segmentio/conf v1.0.0/go.mod h1:y0VyxYAlU2slxCjm7XX7tGKFlN39bwHCZrbOpCcLsr8= -github.com/segmentio/events v2.1.0+incompatible h1:7ns47dgRJMt/JgIXrNU0MiD/NtCGa55lKzWP15dcGnM= -github.com/segmentio/events v2.1.0+incompatible/go.mod h1:npQUbmKYO33tlRpaQNZjgD2mXv0fb2hbOH0CNVs6g2Y= +github.com/segmentio/encoding v0.3.6/go.mod h1:n0JeuIqEQrQoPDGsjo8UNd1iA0U8d8+oHAA4E3G3OxM= +github.com/segmentio/events/v2 v2.6.0 h1:MRPhHWwfLGFjkppjkdCDw2DZVBMyMb/JcBVnDVVNdzc= +github.com/segmentio/events/v2 v2.6.0/go.mod h1:oDngvacuvZ/bPnAq8VKNzvk8ICS1pVVEtQESVcvSL/w= github.com/segmentio/go-snakecase v1.0.0 h1:FSeHpP0sBL3O+MCpxvQZrS5a51WAki6gposZuwVE9L4= github.com/segmentio/go-snakecase v1.0.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto= github.com/segmentio/objconv v1.0.1 h1:QjfLzwriJj40JibCV3MGSEiAoXixbp4ybhwfTB8RXOM= github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys= github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e h1:GNlZqttb0RQTUYTYnSwAMyqgHzYouBGVImRJp8Y43Hg= github.com/segmentio/timers v0.0.0-20180605162245-8ad1428b010e/go.mod h1:/6SKE4F6LzTh32hPOJs0KRJ7MHHWpTZ7wb4PxdjgzaQ= +golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=