Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-01-07 19:37:59 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-01-07 19:37:59 +0300
commitd7dc7ed7201437a3f450bd783800386e01d62661 (patch)
tree8053829c7ba64208917aaf599a912483a4509b95 /logging.go
parent61debe70052f5da9e32acdb4d695ccf56991df9f (diff)
Add simple GitLab Pages daemon with custom CNAME and TLS support
Diffstat (limited to 'logging.go')
-rw-r--r--logging.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/logging.go b/logging.go
new file mode 100644
index 00000000..bee171b2
--- /dev/null
+++ b/logging.go
@@ -0,0 +1,52 @@
+package main
+
+import (
+ "fmt"
+ "net/http"
+ "time"
+)
+
+type loggingResponseWriter struct {
+ rw http.ResponseWriter
+ status int
+ written int64
+ started time.Time
+}
+
+func newLoggingResponseWriter(rw http.ResponseWriter) loggingResponseWriter {
+ return loggingResponseWriter{
+ rw: rw,
+ started: time.Now(),
+ }
+}
+
+func (l *loggingResponseWriter) Header() http.Header {
+ return l.rw.Header()
+}
+
+func (l *loggingResponseWriter) Write(data []byte) (n int, err error) {
+ if l.status == 0 {
+ l.WriteHeader(http.StatusOK)
+ }
+ n, err = l.rw.Write(data)
+ l.written += int64(n)
+ return
+}
+
+func (l *loggingResponseWriter) WriteHeader(status int) {
+ if l.status != 0 {
+ return
+ }
+
+ l.status = status
+ l.rw.WriteHeader(status)
+}
+
+func (l *loggingResponseWriter) Log(r *http.Request) {
+ duration := time.Since(l.started)
+ fmt.Printf("%s %s - - [%s] %q %d %d %q %q %f\n",
+ r.Host, r.RemoteAddr, l.started,
+ fmt.Sprintf("%s %s %s", r.Method, r.RequestURI, r.Proto),
+ l.status, l.written, r.Referer(), r.UserAgent(), duration.Seconds(),
+ )
+}