Documentation ¶
Index ¶
Constants ¶
const ( // MessageKey is the key used to store the log message. MessageKey = "message" // RequestKey is the key used to keep the request if enabled. RequestKey = "request" // ResponseKey is the key used to keep the response if enabled. ResponseKey = "response" // ErrorKey is the key used to store an error. ErrorKey = "error" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Headers ¶ added in v0.0.3
Headers represents key-value pairs in the HTTP headers.
func (Headers) Get ¶ added in v0.0.3
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".
func (Headers) MarshalLogObject ¶ added in v0.0.3
func (h Headers) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject adds the headers in the log.
type LoggerHandler ¶
LoggerHandler creates a logger handler
func (*LoggerHandler) ServeHTTP ¶
func (l *LoggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler and call to the handler to log with a custom http.ResponseWriter that records the response code and the number of bytes sent.
type Option ¶ added in v0.0.11
type Option func(o *options)
Option is the type used to modify logger options.
func WithRedactor ¶ added in v0.0.11
func WithRedactor(fn RedactorFunc) Option
WithRedactor is an option that adds a new redactor to a httplog.
type RawResponseLogger ¶
type RawResponseLogger interface { ResponseLogger Buffer() *bytes.Buffer Response() []byte }
RawResponseLogger defines an interface that a responseWrite can implement to support the capture of the status code, the number of bytes written and extra log entry fields.
func NewRawResponseLogger ¶
func NewRawResponseLogger(w http.ResponseWriter) RawResponseLogger
NewRawResponseLogger wraps the given response writer with the methods to capture the status code, the bytes written, and methods to add new log entries. It won't wrap the response writer if it's already a RawResponseLogger.
type RedactorFunc ¶ added in v0.0.11
type RedactorFunc func(w http.ResponseWriter, r *http.Request)
RedactorFunc is a function that redacts the HTTP request or response logged.
type Request ¶ added in v0.0.3
Request represents an HTTP request, it implements a zapcore.ObjectMarshaller on it.
func NewRequest ¶ added in v0.0.3
NewRequest creates a Request object from an http.Request.
func (*Request) MarshalLogObject ¶ added in v0.0.3
func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject adds the properties of the request in the log.
type Response ¶ added in v0.0.3
Response represents an HTTP response, it implements a zapcore.ObjectMarshaller on it.
func (*Response) MarshalLogObject ¶ added in v0.0.3
func (r *Response) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject adds the properties of the response in the log.
type ResponseLogger ¶
type ResponseLogger interface { http.ResponseWriter Size() int StatusCode() int Fields() map[string]interface{} WithField(key string, value interface{}) WithFields(map[string]interface{}) Field(key string) (interface{}, bool) Request() (*Request, bool) }
ResponseLogger defines an interface that a responseWrite can implement to support the capture of the status code, the number of bytes written and extra log entry fields.
func NewResponseLogger ¶
func NewResponseLogger(w http.ResponseWriter) ResponseLogger
NewResponseLogger wraps the given response writer with methods to capture the status code, the number of bytes written, and methods to add new log entries. It won't wrap the response writer if it's already a ResponseLogger.