@@ -42,7 +42,6 @@ func TraceIDFromContext(ctx context.Context) (string, bool) {
4242
4343type (
4444 LogEntry struct {
45- CacheStatus string
4645 URLKey string
4746 MiscProvider MiscProvider
4847 Error error
@@ -75,6 +74,9 @@ func (m Misc) LogValue() slog.Value {
7574 if m .RefIndex >= 0 && m .RefIndex < len (m .Refs ) {
7675 attrs = append (attrs , slog .Any ("ref" , m .Refs [m .RefIndex ]))
7776 }
77+ if cap (attrs ) > len (attrs ) {
78+ attrs = slices .Clip (attrs )
79+ }
7880 return slog .GroupValue (attrs ... )
7981}
8082
@@ -143,7 +145,6 @@ func (l *Logger) LogCacheHit(req *http.Request, urlKey string, mp MiscProvider)
143145 "Hit; served from cache." ,
144146 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
145147 return CacheStatusHit , req , LogEntry {
146- CacheStatus : CacheStatusHit .Value ,
147148 URLKey : urlKey ,
148149 MiscProvider : mp ,
149150 Error : nil ,
@@ -159,7 +160,6 @@ func (l *Logger) LogCacheMiss(req *http.Request, urlKey string, mp MiscProvider)
159160 "Miss; served from origin." ,
160161 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
161162 return CacheStatusMiss , req , LogEntry {
162- CacheStatus : CacheStatusMiss .Value ,
163163 URLKey : urlKey ,
164164 MiscProvider : mp ,
165165 Error : nil ,
@@ -175,7 +175,6 @@ func (l *Logger) LogCacheStale(req *http.Request, urlKey string, mp MiscProvider
175175 "Stale; served from cache." ,
176176 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
177177 return CacheStatusStale , req , LogEntry {
178- CacheStatus : CacheStatusStale .Value ,
179178 URLKey : urlKey ,
180179 MiscProvider : mp ,
181180 Error : nil ,
@@ -191,7 +190,6 @@ func (l *Logger) LogCacheStaleIfError(req *http.Request, urlKey string, mp MiscP
191190 "Stale; served from cache; stale-if-error policy applied." ,
192191 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
193192 return CacheStatusStale , req , LogEntry {
194- CacheStatus : CacheStatusStale .Value ,
195193 URLKey : urlKey ,
196194 MiscProvider : mp ,
197195 Error : nil ,
@@ -207,7 +205,6 @@ func (l *Logger) LogCacheStaleRevalidate(req *http.Request, urlKey string, mp Mi
207205 "Stale; served from cache; revalidating." ,
208206 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
209207 return CacheStatusStale , req , LogEntry {
210- CacheStatus : CacheStatusStale .Value ,
211208 URLKey : urlKey ,
212209 MiscProvider : mp ,
213210 Error : nil ,
@@ -223,7 +220,6 @@ func (l *Logger) LogCacheRevalidated(req *http.Request, urlKey string, mp MiscPr
223220 "Revalidated; served cached response." ,
224221 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
225222 return CacheStatusRevalidated , req , LogEntry {
226- CacheStatus : CacheStatusRevalidated .Value ,
227223 URLKey : urlKey ,
228224 MiscProvider : mp ,
229225 Error : nil ,
@@ -239,7 +235,6 @@ func (l *Logger) LogCacheBypass(msg string, req *http.Request, urlKey string, mp
239235 msg ,
240236 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
241237 return CacheStatusBypass , req , LogEntry {
242- CacheStatus : CacheStatusBypass .Value ,
243238 URLKey : urlKey ,
244239 MiscProvider : mp ,
245240 Error : nil ,
@@ -261,7 +256,6 @@ func (l *Logger) LogCacheError(
261256 msg ,
262257 LogFunc (func () (CacheStatus , * http.Request , LogEntry ) {
263258 return CacheStatus {Value : "error" }, req , LogEntry {
264- CacheStatus : "error" ,
265259 URLKey : urlKey ,
266260 MiscProvider : mp ,
267261 Error : err ,
@@ -293,7 +287,7 @@ func (l *Logger) logCache(ctx context.Context, level slog.Level, msg string, lp
293287 slog .String ("host" , req .Host ),
294288 ),
295289 groupAttrs ("cache" ,
296- slog .String ("status" , cl . CacheStatus ),
290+ slog .Any ("status" , event ),
297291 slog .String ("url_key" , cl .URLKey ),
298292 ),
299293 )
0 commit comments