Merge pull request #619 from jangie/consistent-duration-logging

Make duration logging consistent
This commit is contained in:
Vincent Demeester 2016-08-15 18:30:25 +02:00 committed by GitHub
commit fb3bad3887
2 changed files with 7 additions and 5 deletions

View file

@ -75,7 +75,7 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1)) c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1))
c.Assert(strings.HasPrefix(tokens[10], "frontend"), checker.True) c.Assert(strings.HasPrefix(tokens[10], "frontend"), checker.True)
c.Assert(strings.HasPrefix(tokens[11], "http://127.0.0.1:808"), checker.True) c.Assert(strings.HasPrefix(tokens[11], "http://127.0.0.1:808"), checker.True)
c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True) c.Assert(regexp.MustCompile("^\\d+ms$").MatchString(tokens[12]), checker.True)
} }
} }
c.Assert(count, checker.Equals, 3) c.Assert(count, checker.Equals, 3)

View file

@ -3,8 +3,6 @@ package middlewares
import ( import (
"bufio" "bufio"
"fmt" "fmt"
log "github.com/Sirupsen/logrus"
"github.com/streamrail/concurrent-map"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -13,6 +11,9 @@ import (
"strings" "strings"
"sync/atomic" "sync/atomic"
"time" "time"
log "github.com/Sirupsen/logrus"
"github.com/streamrail/concurrent-map"
) )
const ( const (
@ -138,8 +139,9 @@ func (fblh frontendBackendLoggingHandler) ServeHTTP(rw http.ResponseWriter, req
size := infoRw.GetSize() size := infoRw.GetSize()
elapsed := time.Now().UTC().Sub(startTime.UTC()) elapsed := time.Now().UTC().Sub(startTime.UTC())
fmt.Fprintf(fblh.writer, `%s - %s [%s] "%s %s %s" %d %d "%s" "%s" %s "%s" "%s" %s%s`, elapsedMillis := elapsed.Nanoseconds() / 1000000
host, username, ts, method, uri, proto, status, size, referer, agent, fblh.reqid, frontend, backend, elapsed, "\n") fmt.Fprintf(fblh.writer, `%s - %s [%s] "%s %s %s" %d %d "%s" "%s" %s "%s" "%s" %dms%s`,
host, username, ts, method, uri, proto, status, size, referer, agent, fblh.reqid, frontend, backend, elapsedMillis, "\n")
} }