MCPcopy Create free account
hub / github.com/zalando/skipper / LogAccess

Method LogAccess

logging/access.go:144–210  ·  view source on GitHub ↗

LogAccess logs an access event in Apache combined log format (with a minor customization with the duration). Additional allows to provide extra data that may be also logged, depending on the specific log format.

(entry *AccessEntry, additional map[string]any)

Source from the content-addressed store, hash-verified

142// LogAccess logs an access event in Apache combined log format (with a minor customization with the duration).
143// Additional allows to provide extra data that may be also logged, depending on the specific log format.
144func (alog *AccessLogger) LogAccess(entry *AccessEntry, additional map[string]any) {
145 if entry == nil {
146 return
147 }
148
149 host := ""
150 method := ""
151 uri := ""
152 proto := ""
153 referer := ""
154 userAgent := ""
155 requestedHost := ""
156 flowID := ""
157 auditHeader := ""
158
159 ts := entry.RequestTime.Format(dateFormat)
160 status := entry.StatusCode
161 responseSize := entry.ResponseSize
162 duration := int64(entry.Duration / time.Millisecond)
163 authUser := entry.AuthUser
164
165 if entry.Request != nil {
166 host = remoteHost(entry.Request)
167 method = entry.Request.Method
168 proto = entry.Request.Proto
169 referer = entry.Request.Referer()
170 userAgent = entry.Request.UserAgent()
171 requestedHost = entry.Request.Host
172 flowID = entry.Request.Header.Get(flowidFilter.HeaderName)
173
174 uri = entry.Request.RequestURI
175 if alog.stripQuery {
176 uri = stripQueryString(uri)
177 } else if keys, ok := additional[al.KeyMaskedQueryParams].(map[string]struct{}); ok && len(keys) > 0 {
178 uri = maskQueryParams(entry.Request, keys)
179 }
180
181 auditHeader = entry.Request.Header.Get(logFilter.UnverifiedAuditHeader)
182 }
183
184 logData := logrus.Fields{
185 "timestamp": ts,
186 "host": host,
187 "method": method,
188 "uri": uri,
189 "proto": proto,
190 "referer": referer,
191 "user-agent": userAgent,
192 "status": status,
193 "response-size": responseSize,
194 "requested-host": requestedHost,
195 "duration": duration,
196 "flow-id": flowID,
197 "audit": auditHeader,
198 "auth-user": authUser,
199 }
200
201 delete(additional, al.KeyMaskedQueryParams)

Callers 4

testAccessLogExtendedFunction · 0.95
ServeHTTPMethod · 0.80

Calls 8

stripQueryStringFunction · 0.85
maskQueryParamsFunction · 0.85
WithFieldsMethod · 0.80
ContextMethod · 0.80
remoteHostFunction · 0.70
GetMethod · 0.65
FormatMethod · 0.45
CopyMethod · 0.45

Tested by 3

testAccessLogExtendedFunction · 0.76