From 924805845be63b1dc6443338704e20903c21d7c3 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 9 Dec 2024 15:18:19 -0800 Subject: [PATCH] Remove use of zap in httpPlusdb example (#1391) Unify on slog for project logging. --- examples/httpPlusdb/go.mod | 7 +------ examples/httpPlusdb/go.sum | 9 --------- examples/httpPlusdb/main.go | 16 ++++------------ 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/examples/httpPlusdb/go.mod b/examples/httpPlusdb/go.mod index e558dbe53..6e0cfb620 100644 --- a/examples/httpPlusdb/go.mod +++ b/examples/httpPlusdb/go.mod @@ -2,9 +2,4 @@ module go.opentelemetry.io/auto/examples/httpPlusdb go 1.20 -require ( - github.com/mattn/go-sqlite3 v1.14.24 - go.uber.org/zap v1.27.0 -) - -require go.uber.org/multierr v1.11.0 // indirect +require github.com/mattn/go-sqlite3 v1.14.24 diff --git a/examples/httpPlusdb/go.sum b/examples/httpPlusdb/go.sum index 79e7b8d77..9dcdc9b60 100644 --- a/examples/httpPlusdb/go.sum +++ b/examples/httpPlusdb/go.sum @@ -1,11 +1,2 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -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= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/httpPlusdb/main.go b/examples/httpPlusdb/main.go index ae8f27228..f07716dd1 100644 --- a/examples/httpPlusdb/main.go +++ b/examples/httpPlusdb/main.go @@ -6,11 +6,11 @@ package main import ( "database/sql" "fmt" + "log/slog" "net/http" "os" _ "github.com/mattn/go-sqlite3" - "go.uber.org/zap" ) const ( @@ -84,7 +84,7 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) { panic(err) } - logger.Info("queryDb called") + slog.Info("queryDb called") for rows.Next() { var id int var firstName string @@ -99,8 +99,6 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) { } } -var logger *zap.Logger - func setupHandler(s *Server) *http.ServeMux { mux := http.NewServeMux() mux.HandleFunc("/query_db", s.queryDb) @@ -108,18 +106,12 @@ func setupHandler(s *Server) *http.ServeMux { } func main() { - var err error - logger, err = zap.NewDevelopment() - if err != nil { - fmt.Printf("error creating zap logger, error:%v", err) - return - } port := fmt.Sprintf(":%d", 8080) - logger.Info("starting http server", zap.String("port", port)) + slog.Info("starting http server", "port", port) s := NewServer() mux := setupHandler(s) if err := http.ListenAndServe(port, mux); err != nil { - logger.Error("error running server", zap.Error(err)) + slog.Error("error running server", "error", err) } }