Documentation ¶
Overview ¶
Package log implements the bult-in logging handler of orujo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
A LogHandler is a orujo built-in handler that provides logging features.
func NewLogHandler ¶
func NewLogHandler(logger *log.Logger, fmt string) LogHandler
NewLogHandler returns a new LogHandler. It accepts a log.Logger, that will be used to write the generated log records using the format specified by the argument fmt.
fmt must be a valid text template, which is parsed when NewLogHandler is called. Note that if fmt is not valid, NewLogHandler will panic. For more information regarding templates, see the documentation of the package "text/template".
The template will be executed passing the following structure:
struct { Resp http.ResponseWriter Req *http.Request Errors []error }
This way, the LogHandler has access to the http.ResponseWriter, the http.Request and a errors slice containing all the errors registered during the handlers pipe execution.
E.g.:
const logLine = `{{.Req.RemoteAddr}} - {{.Req.Method}} {{.Req.RequestURI}} {{range $err := .Errors}} Err: {{$err}} {{end}}` logger := log.New(os.Stdout, "[ORUJO] ", log.LstdFlags) logHandler := orujolog.NewLogHandler(logger, logLine)
func (LogHandler) ServeHTTP ¶
func (h LogHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP will execute the log template when the handler is used.