summaryrefslogtreecommitdiff
path: root/internal/router
diff options
context:
space:
mode:
authorLibravatar Daenney <daenney@users.noreply.github.com>2023-02-17 12:02:29 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-17 12:02:29 +0100
commit68e6d08c768b789987a753d42f66caf73ce10ee1 (patch)
tree1c9eb6da6c326266d653de80684c3aec58922638 /internal/router
parent[bugfix] Set 'discoverable' properly on API accounts (#1511) (diff)
downloadgotosocial-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')
-rw-r--r--internal/router/router.go14
-rw-r--r--internal/router/template.go6
2 files changed, 10 insertions, 10 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
}
diff --git a/internal/router/template.go b/internal/router/template.go
index dedfd2011..88adb8a9b 100644
--- a/internal/router/template.go
+++ b/internal/router/template.go
@@ -87,7 +87,7 @@ func noescapeAttr(str string) template.HTMLAttr {
func timestamp(stamp string) string {
t, err := util.ParseISO8601(stamp)
if err != nil {
- log.Errorf("error parsing timestamp %s: %s", stamp, err)
+ log.Errorf(nil, "error parsing timestamp %s: %s", stamp, err)
return badTimestamp
}
@@ -110,7 +110,7 @@ func timestamp(stamp string) string {
func timestampPrecise(stamp string) string {
t, err := util.ParseISO8601(stamp)
if err != nil {
- log.Errorf("error parsing timestamp %s: %s", stamp, err)
+ log.Errorf(nil, "error parsing timestamp %s: %s", stamp, err)
return badTimestamp
}
return t.Local().Format(dateYearTime)
@@ -119,7 +119,7 @@ func timestampPrecise(stamp string) string {
func timestampVague(stamp string) string {
t, err := util.ParseISO8601(stamp)
if err != nil {
- log.Errorf("error parsing timestamp %s: %s", stamp, err)
+ log.Errorf(nil, "error parsing timestamp %s: %s", stamp, err)
return badTimestamp
}
return t.Format(monthYear)