From 9e63a674e18746024e9211481cf6759a9865eb0c Mon Sep 17 00:00:00 2001 From: johnabass Date: Tue, 19 Nov 2024 20:33:55 -0800 Subject: [PATCH] added user-agent and the sallust default fields to the request logger --- xhttp/xhttpserver/server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xhttp/xhttpserver/server.go b/xhttp/xhttpserver/server.go index 01cac08..d6edc1e 100644 --- a/xhttp/xhttpserver/server.go +++ b/xhttp/xhttpserver/server.go @@ -53,12 +53,17 @@ type Options struct { // NewServerChain produces the standard constructor chain for a server, primarily using configuration. func NewServerChain(o Options, l *zap.Logger, fbs ...sallusthttp.FieldBuilder) alice.Chain { bs := sallusthttp.Builders{} + bs.AddFields(fbs...) + bs.Add(sallusthttp.DefaultFields) + bs.Add(func(r *http.Request, l *zap.Logger) *zap.Logger { + return l.With(zap.String("userAgent", r.UserAgent())) + }) + chain := alice.New( ResponseHeaders{Header: o.Header}.Then, Busy{MaxConcurrentRequests: o.MaxConcurrentRequests}.Then, ) - bs.AddFields(fbs...) if !o.DisableTracking { chain = chain.Append(UseTrackingWriter) }