Documentation ¶
Index ¶
Constants ¶
const ( // ReqTimeField contains time of request receiving. ReqTimeField = RequestField("req_time") // IDField contains ID of the request. IDField = RequestField("req_id") // RemoteIPField contains request remote IP. RemoteIPField = RequestField("req_remote_ip") // HostField contains request host. HostField = RequestField("req_host") // URIField contains full URI of the request. URIField = RequestField("req_uri") // CompactURIField contains request arguments which are compacted (only keys). CompactURIField = RequestField("req_uri_compact") // MethodField contains request method. MethodField = RequestField("req_method") // PathField contains path of request. PathField = RequestField("req_path") // BytesInField contains size of request in bytes. BytesInField = RequestField("req_bytes_in") // AuthField contains auth header for request. AuthField = RequestField("req_auth_header") )
const ( // StatusField contains status code. StatusField = ResponseField("res_status") // BytesOutField contains size of response in bytes. BytesOutField = ResponseField("res_bytes_out") // ResTimeField contains time returning response or redirecting. ResTimeField = ResponseField("res_time") // ContentTypeField contains content-type of the response. ContentTypeField = ResponseField("res_content_type") // LocationField contains full redirection URL in case of redirection response. LocationField = ResponseField("res_location") // LocationCompactArgsField contains arguments of redirection URL in case of redirection response in compacted form (only keys). LocationCompactArgsField = ResponseField("res_location_compact") // LocationHostField contains host of redirection URL in case of redirection response. LocationHostField = ResponseField("res_location_host") )
Variables ¶
var DefaultRequestFields = []RequestField{ ReqTimeField, IDField, RemoteIPField, HostField, CompactURIField, MethodField, PathField, BytesInField, AuthField, }
DefaultRequestFields is a list for recommended configuration of request fields.
var DefaultResponseFields = []ResponseField{ StatusField, BytesOutField, ResTimeField, ContentTypeField, LocationCompactArgsField, LocationHostField, }
DefaultResponseFields is a list for recommended configuration of response fields.
Functions ¶
func RegisterMiddleware ¶
RegisterMiddleware registers handler that will log request at the beginning and served response at the request end.
Types ¶
type Config ¶
type Config struct { // RequestFields specifies request fields that should be logged when request is received (before server handling). RequestFields []RequestField // ResponseFields specifies response fields that should be logged when response is returned/redirected // (right after server handling). ResponseFields []ResponseField // ResponseReqFields specifies request fields that should be logged when response is returned/redirected // (right after server handling). It is useful if you want to log only once per request. (common logging technique) ResponseReqFields []RequestField }
Config is a configuration for httplog.
func DefaultReqResConfig ¶
func DefaultReqResConfig() Config
DefaultReqResConfig is configuration for logging one entry when request is received and one when response is written.
func DefaultResponseOnlyConfig ¶
func DefaultResponseOnlyConfig() Config
DefaultResponseOnlyConfig is configuration for logging only an entry when response is written.
type FieldLogger ¶
type FieldLogger interface { WithFields(fields Fields) FieldLogger Log(args ...interface{}) }
The FieldLogger interface generalizes structured logging used by httplog.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an instance for httplog to register middleware and wrap response.
func (*Logger) RequestHandler ¶
func (l *Logger) RequestHandler() func(w http.ResponseWriter, r *http.Request)
RequestHandler handles request log entry. Should be places at before serving response.
func (*Logger) WrapResponse ¶
func (l *Logger) WrapResponse(w http.ResponseWriter, r *http.Request) http.ResponseWriter
WrapResponse wraps ResponseWriter. It is the only way to get details about response without including custom code in user handlers.
type MockFieldLogger ¶
MockFieldLogger is an autogenerated mock type for the FieldLogger type
func (*MockFieldLogger) Log ¶
func (_m *MockFieldLogger) Log(args ...interface{})
Log provides a mock function with given fields: args
func (*MockFieldLogger) WithError ¶
func (_m *MockFieldLogger) WithError(err error) FieldLogger
WithError provides a mock function with given fields: err
func (*MockFieldLogger) WithFields ¶
func (_m *MockFieldLogger) WithFields(fields Fields) FieldLogger
WithFields provides a mock function with given fields: fields
type RequestField ¶
type RequestField string
RequestField is a log field that can be deducted from http.Request.
type ResponseField ¶
type ResponseField string
ResponseField is a log field that can be deducted from response. It is done by wrapping http.ResponseWriter.