commit e462a16204abd59b33f54658eef83fccdbac6801 Author: Vincent Batts Date: Tue Jun 18 15:02:56 2013 -0400 adding a request logger diff --git a/log-request.go b/log-request.go new file mode 100644 index 0000000..d1d380b --- /dev/null +++ b/log-request.go @@ -0,0 +1,35 @@ +package httplog + +import ( + "fmt" + "net/http" + "strings" + "time" +) + +/* kindof a common log type output */ +func LogRequest(r *http.Request, statusCode int) { + var addr string + var user_agent string + + user_agent = "" + addr = r.RemoteAddr + + for k, v := range r.Header { + if k == "User-Agent" { + user_agent = strings.Join(v, " ") + } + if k == "X-Forwarded-For" { + addr = strings.Join(v, " ") + } + } + + fmt.Printf("%s - - [%s] \"%s %s\" \"%s\" %d %d\n", + addr, + time.Now(), + r.Method, + r.URL.String(), + user_agent, + statusCode, + r.ContentLength) +}