back interdiff of round #1 and #0

appview: improve the logging situation a bit #654

closed
opened by oppi.li targeting master from push-nsovyllpxlwk

needs a lot more work, but we now inject slog in several places.

Signed-off-by: oppiliappan me@oppi.li

files
appview
cmd
appview
spindle
jetstream
nix
xrpc
serviceauth
ERROR
appview/db/db.go

Failed to calculate interdiff for this file.

ERROR
appview/ingester.go

Failed to calculate interdiff for this file.

ERROR
appview/issues/issues.go

Failed to calculate interdiff for this file.

ERROR
appview/labels/labels.go

Failed to calculate interdiff for this file.

ERROR
appview/notifications/notifications.go

Failed to calculate interdiff for this file.

ERROR
appview/pages/pages.go

Failed to calculate interdiff for this file.

ERROR
appview/pipelines/pipelines.go

Failed to calculate interdiff for this file.

ERROR
appview/pulls/pulls.go

Failed to calculate interdiff for this file.

ERROR
appview/repo/index.go

Failed to calculate interdiff for this file.

ERROR
appview/repo/repo.go

Failed to calculate interdiff for this file.

ERROR
appview/signup/signup.go

Failed to calculate interdiff for this file.

ERROR
appview/state/knotstream.go

Failed to calculate interdiff for this file.

ERROR
appview/state/router.go

Failed to calculate interdiff for this file.

ERROR
appview/state/spindlestream.go

Failed to calculate interdiff for this file.

ERROR
appview/state/state.go

Failed to calculate interdiff for this file.

ERROR
cmd/appview/main.go

Failed to calculate interdiff for this file.

ERROR
go.mod

Failed to calculate interdiff for this file.

ERROR
go.sum

Failed to calculate interdiff for this file.

ERROR
jetstream/jetstream.go

Failed to calculate interdiff for this file.

ERROR
nix/gomod2nix.toml

Failed to calculate interdiff for this file.

ERROR
xrpc/serviceauth/service_auth.go

Failed to calculate interdiff for this file.

NEW
appview/state/login.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "log" 6 5 "net/http" 7 6 "strings" 8 7 ··· 10 9 ) 11 10 12 11 func (s *State) Login(w http.ResponseWriter, r *http.Request) { 12 + l := s.logger.With("handler", "Login") 13 + 13 14 switch r.Method { 14 15 case http.MethodGet: 15 16 returnURL := r.URL.Query().Get("return_url") ··· 32 33 33 34 // basic handle validation 34 35 if !strings.Contains(handle, ".") { 35 - log.Println("invalid handle format", "raw", handle) 36 + l.Error("invalid handle format", "raw", handle) 36 37 s.pages.Notice( 37 38 w, 38 39 "login-msg", ··· 52 53 } 53 54 54 55 func (s *State) Logout(w http.ResponseWriter, r *http.Request) { 56 + l := s.logger.With("handler", "Logout") 57 + 55 58 err := s.oauth.DeleteSession(w, r) 56 59 if err != nil { 57 - log.Println("failed to logout", "err", err) 60 + l.Error("failed to logout", "err", err) 58 61 } else { 59 - log.Println("logged out successfully") 62 + l.Info("logged out successfully") 60 63 } 61 64 62 65 s.pages.HxRedirect(w, "/login")
NEW
cmd/spindle/main.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "log/slog" 5 6 "os" 6 7 7 - "tangled.org/core/log" 8 + tlog "tangled.org/core/log" 8 9 "tangled.org/core/spindle" 9 10 _ "tangled.org/core/tid" 10 11 ) 11 12 12 13 func main() { 13 - ctx := log.NewContext(context.Background(), "spindle") 14 + logger := tlog.New("spindl3") 15 + slog.SetDefault(logger) 16 + 17 + ctx := context.Background() 18 + ctx = tlog.IntoContext(ctx, logger) 19 + 14 20 err := spindle.Run(ctx) 15 21 if err != nil { 16 - log.FromContext(ctx).Error("error running spindle", "error", err) 22 + logger.Error("error running spindle", "error", err) 17 23 os.Exit(-1) 18 24 } 19 25 }