Blame view
middleware_log.go
652 Bytes
feb3471e7 refactored loggin... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
package webutility import ( "net/http" "time" "git.to-net.rs/marko.tikvic/gologger" ) var trafficLogger *gologger.Logger func EnableLogging(log string) (err error) { trafficLogger, err = gologger.New(log, gologger.MaxLogSize5MB) return err } func Log(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { t1 := time.Now() claims, _ := GetTokenClaims(req) in := trafficLogger.RequestLog(req, claims.Username) wRec := WrapWithStatusRecorder(w) h(wRec, req) t2 := time.Now() out := trafficLogger.ResponseLog(wRec.Status(), t2.Sub(t1), 0) trafficLogger.LogHTTPTraffic(in, out) } } |