tsweb: mark AccessLogRecord fields as omitempty (#5250)

If the field is the zero value, then avoid serializing the field.
This reduces verbosity in server logs.

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
pull/5259/head
Joe Tsai 2 years ago committed by GitHub
parent 5d0e3d379c
commit a794963e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,34 +18,34 @@ type AccessLogRecord struct {
// include the entire lifetime of the underlying connection in // include the entire lifetime of the underlying connection in
// cases like connection hijacking, only the lifetime of the HTTP // cases like connection hijacking, only the lifetime of the HTTP
// request handler. // request handler.
Seconds float64 `json:"duration"` Seconds float64 `json:"duration,omitempty"`
// The client's ip:port. // The client's ip:port.
RemoteAddr string `json:"remote_addr"` RemoteAddr string `json:"remote_addr,omitempty"`
// The HTTP protocol version, usually "HTTP/1.1 or HTTP/2". // The HTTP protocol version, usually "HTTP/1.1 or HTTP/2".
Proto string `json:"proto"` Proto string `json:"proto,omitempty"`
// Whether the request was received over TLS. // Whether the request was received over TLS.
TLS bool `json:"tls"` TLS bool `json:"tls,omitempty"`
// The target hostname in the request. // The target hostname in the request.
Host string `json:"host"` Host string `json:"host,omitempty"`
// The HTTP method invoked. // The HTTP method invoked.
Method string `json:"method"` Method string `json:"method,omitempty"`
// The unescaped request URI, including query parameters. // The unescaped request URI, including query parameters.
RequestURI string `json:"request_uri"` RequestURI string `json:"request_uri,omitempty"`
// The client's user-agent // The client's user-agent
UserAgent string `json:"user_agent"` UserAgent string `json:"user_agent,omitempty"`
// Where the client was before making this request. // Where the client was before making this request.
Referer string `json:"referer"` Referer string `json:"referer,omitempty"`
// The HTTP response code sent to the client. // The HTTP response code sent to the client.
Code int `json:"code"` Code int `json:"code,omitempty"`
// Number of bytes sent in response body to client. If the request // Number of bytes sent in response body to client. If the request
// was hijacked, only includes bytes sent up to the point of // was hijacked, only includes bytes sent up to the point of
// hijacking. // hijacking.
Bytes int `json:"bytes"` Bytes int `json:"bytes,omitempty"`
// Error encountered during request processing. // Error encountered during request processing.
Err string `json:"err"` Err string `json:"err,omitempty"`
} }
// String returns m as a JSON string. // String returns m as a JSON string.

Loading…
Cancel
Save