Documentation ¶
Overview ¶
Package logutil provides logging utilities
Index ¶
- func GetReqID(ctx context.Context) string
- type Logger
- func (l *Logger) Output(calldepth int, s string) error
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) RequestPrintf(r *http.Request, format string, v ...interface{})
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) StartRequest(r *http.Request)
- func (l *Logger) TraceFunc()
- func (l *Logger) TraceRequest(r *http.Request)
- func (l *Logger) Writer() io.Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetReqID ¶
GetReqID piggybacks chi/middleware's GetReqID by obtaining the request ID of the request (if present) and strips away the machine name part of the string.
The Request ID is initially set by the chi middleware.RequestID middleware function, this function merely picks up on it. If middleware.RequestID was not called prior to this, GetReqID will simply return an empty string
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.
func (*Logger) Printf ¶
Printf is a wrapper around log.Logger.Printf. It will print nothing if the output is set to ioutil.Discard, allowing for levelled logging. https://stackoverflow.com/a/42762815
func (*Logger) Println ¶
func (l *Logger) Println(v ...interface{})
Println is a wrapper around log.Logger.Println. It will print nothing if the output is set to ioutil.Discard, allowing for levelled logging.
func (*Logger) RequestPrintf ¶
RequestPrintf is like Printf, but it will also print out the request ID of the current request.
func (*Logger) StartRequest ¶
StartRequest should be called in the middleware at the very start of the request, so that it cleanly delineates between inidividual requests.
func (*Logger) TraceFunc ¶
func (l *Logger) TraceFunc()
TraceFunc is like TraceRequest, except it is for functions that don't take in a *http.Request. This means it will not print the request ID, only the function, file and line number of where TraceFunc was called.
func (*Logger) TraceRequest ¶
TraceRequest should be called at the start of every handler function that accepts a *http.Request. It will print the function, file and line number of where the TraceRequest call was called, allowing the user to trace the chain functions being called in a request.
It will also print out the any request ID found in the request context.