logWithRequest information from the request and context as fields.
(r *http.Request)
| 57 | |
| 58 | // logWithRequest information from the request and context as fields. |
| 59 | func (l Log) logWithRequest(r *http.Request) log.Logger { |
| 60 | localLog := l.Log |
| 61 | traceID, ok := tracing.ExtractSampledTraceID(r.Context()) |
| 62 | if ok { |
| 63 | localLog = log.With(localLog, "trace_id", traceID) |
| 64 | } else if traceID != "" { |
| 65 | localLog = log.With(localLog, "trace_id_unsampled", traceID) |
| 66 | } |
| 67 | |
| 68 | if l.SourceIPs != nil { |
| 69 | ips := l.SourceIPs.Get(r) |
| 70 | if ips != "" { |
| 71 | localLog = log.With(localLog, "sourceIPs", ips) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return user.LogWith(r.Context(), localLog) |
| 76 | } |
| 77 | |
| 78 | // Wrap implements Middleware |
| 79 | func (l Log) Wrap(next http.Handler) http.Handler { |