Browse Source

router logger, log username taken from cookie

Piotr Popieluch 10 years ago
parent
commit
207c1a20ee
1 changed files with 6 additions and 1 deletions
  1. 6 1
      pkg/middleware/logger.go

+ 6 - 1
pkg/middleware/logger.go

@@ -32,7 +32,12 @@ func Logger() macaron.Handler {
 		rw := res.(macaron.ResponseWriter)
 		c.Next()
 
-		content := fmt.Sprintf("Completed %s \"%s %s %s\" %v %s %d bytes in %dus", c.RemoteAddr(), req.Method, req.URL.Path, req.Proto, rw.Status(), http.StatusText(rw.Status()), rw.Size(), time.Since(start)/time.Microsecond)
+		uname := c.GetCookie(setting.CookieUserName)
+		if len(uname) == 0 {
+			uname = "-"
+		}
+
+		content := fmt.Sprintf("Completed %s %s \"%s %s %s\" %v %s %d bytes in %dus", c.RemoteAddr(), uname, req.Method, req.URL.Path, req.Proto, rw.Status(), http.StatusText(rw.Status()), rw.Size(), time.Since(start)/time.Microsecond)
 
 		switch rw.Status() {
 		case 200, 304: