diff options
author | 2023-02-17 12:02:29 +0100 | |
---|---|---|
committer | 2023-02-17 12:02:29 +0100 | |
commit | 68e6d08c768b789987a753d42f66caf73ce10ee1 (patch) | |
tree | 1c9eb6da6c326266d653de80684c3aec58922638 /internal/router/router.go | |
parent | [bugfix] Set 'discoverable' properly on API accounts (#1511) (diff) | |
download | gotosocial-68e6d08c768b789987a753d42f66caf73ce10ee1.tar.xz |
[feature] Add a request ID and include it in logs (#1476)
This adds a lightweight form of tracing to GTS. Each incoming request is
assigned a Request ID which we then pass on and log in all our log
lines. Any function that gets called downstream from an HTTP handler
should now emit a requestID=value pair whenever it logs something.
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/router/router.go')
-rw-r--r-- | internal/router/router.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/internal/router/router.go b/internal/router/router.go index 5225214ab..0b9b63494 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -101,10 +101,10 @@ func (r *router) Start() { ) // Start the LetsEncrypt autocert manager HTTP server. - log.Infof("letsencrypt listening on %s", srv.Addr) + log.Infof(nil, "letsencrypt listening on %s", srv.Addr) if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { - log.Fatalf("letsencrypt: listen: %s", err) + log.Fatalf(nil, "letsencrypt: listen: %s", err) } }() @@ -119,23 +119,23 @@ func (r *router) Start() { r.srv.Handler = debug.WithPprof(r.srv.Handler) if debug.DEBUG { // Profiling requires timeouts longer than 30s, so reset these. - log.Warn("resetting http.Server{} timeout to support profiling") + log.Warn(nil, "resetting http.Server{} timeout to support profiling") r.srv.ReadTimeout = 0 r.srv.WriteTimeout = 0 } // Start the main listener. go func() { - log.Infof("listening on %s", r.srv.Addr) + log.Infof(nil, "listening on %s", r.srv.Addr) if err := listen(); err != nil && err != http.ErrServerClosed { - log.Fatalf("listen: %s", err) + log.Fatalf(nil, "listen: %s", err) } }() } // Stop shuts down the router nicely func (r *router) Stop(ctx context.Context) error { - log.Infof("shutting down http router with %s grace period", shutdownTimeout) + log.Infof(nil, "shutting down http router with %s grace period", shutdownTimeout) timeout, cancel := context.WithTimeout(ctx, shutdownTimeout) defer cancel() @@ -143,7 +143,7 @@ func (r *router) Stop(ctx context.Context) error { return fmt.Errorf("error shutting down http router: %s", err) } - log.Info("http router closed connections and shut down gracefully") + log.Info(nil, "http router closed connections and shut down gracefully") return nil } |