Skip to content

Commit

Permalink
Merge 9af4254 into 20d3c39
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Mancke committed Jun 21, 2016
2 parents 20d3c39 + 9af4254 commit f39349c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions logging/log_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Test_LogMiddleware_Panic(t *testing.T) {
data := logRecordFromBuffer(b)
a.Contains(data.Error, "logging.Test_LogMiddleware_Panic.func1")
a.Contains(data.Error, "runtime error: index out of range")
a.Contains(data.Message, "ERROR GET /foo")
a.Contains(data.Message, "ERROR ->GET /foo")
a.Equal(data.Level, "error")
}

Expand All @@ -50,7 +50,7 @@ func Test_LogMiddleware_Log_implicit200(t *testing.T) {

data := logRecordFromBuffer(b)
a.Equal("", data.Error)
a.Equal("200 GET /foo", data.Message)
a.Equal("200 ->GET /foo", data.Message)
a.Equal(200, data.ResponseStatus)
a.Equal("info", data.Level)
}
Expand All @@ -73,7 +73,7 @@ func Test_LogMiddleware_Log_404(t *testing.T) {

data := logRecordFromBuffer(b)
a.Equal("", data.Error)
a.Equal("404 GET /foo", data.Message)
a.Equal("404 ->GET /foo", data.Message)
a.Equal(404, data.ResponseStatus)
a.Equal("warning", data.Level)
}
8 changes: 4 additions & 4 deletions logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func Access(r *http.Request, start time.Time, statusCode int) {

var msg string
if len(r.URL.RawQuery) == 0 {
msg = fmt.Sprintf("%v %v %v", statusCode, r.Method, r.URL.Path)
msg = fmt.Sprintf("%v ->%v %v", statusCode, r.Method, r.URL.Path)
} else {
msg = fmt.Sprintf("%v %v %v?...", statusCode, r.Method, r.URL.Path)
msg = fmt.Sprintf("%v ->%v %v?...", statusCode, r.Method, r.URL.Path)
}

if statusCode >= 200 && statusCode <= 399 {
Expand All @@ -61,7 +61,7 @@ func Access(r *http.Request, start time.Time, statusCode int) {
// AccessError logs an error while accessing
func AccessError(r *http.Request, start time.Time, err error) {
e := access(r, start, 0, err)
e.Errorf("ERROR %v %v", r.Method, r.URL.Path)
e.Errorf("ERROR ->%v %v", r.Method, r.URL.Path)
}

func access(r *http.Request, start time.Time, statusCode int, err error) *logrus.Entry {
Expand Down Expand Up @@ -131,7 +131,7 @@ func Call(r *http.Request, resp *http.Response, start time.Time, err error) {
fields["response_status"] = resp.StatusCode
fields["content_type"] = resp.Header.Get("Content-Type")
e := Logger.WithFields(fields)
msg := fmt.Sprintf("%v %v %v", resp.StatusCode, r.Method, r.URL.String())
msg := fmt.Sprintf("%v %v-> %v", resp.StatusCode, r.Method, r.URL.String())

if resp.StatusCode >= 200 && resp.StatusCode <= 399 {
e.Info(msg)
Expand Down
8 changes: 4 additions & 4 deletions logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Test_Logger_Call(t *testing.T) {
a.Equal("", data.Error)
a.Equal("www.example.org", data.Host)
a.Equal("GET", data.Method)
a.Equal("404 GET http://www.example.org/foo?q=bar", data.Message)
a.Equal("404 GET-> http://www.example.org/foo?q=bar", data.Message)
a.Equal(404, data.ResponseStatus)
a.Equal("call", data.Type)
a.Equal("/foo?q=bar", data.URL)
Expand Down Expand Up @@ -147,7 +147,7 @@ func Test_Logger_Access(t *testing.T) {
a.Equal("www.example.org", data.Host)
a.Equal("GET", data.Method)
a.Equal("HTTP/1.1", data.Proto)
a.Equal("201 GET /foo?...", data.Message)
a.Equal("201 ->GET /foo?...", data.Message)
a.Equal("127.0.0.1", data.RemoteIp)
a.Equal(201, data.ResponseStatus)
a.Equal("access", data.Type)
Expand All @@ -170,7 +170,7 @@ func Test_Logger_Access_ErrorCases(t *testing.T) {
// then: all fields match
data := logRecordFromBuffer(b)
a.Equal("warning", data.Level)
a.Equal("404 GET /foo", data.Message)
a.Equal("404 ->GET /foo", data.Message)

// when a status 500 is logged
b.Reset()
Expand All @@ -186,7 +186,7 @@ func Test_Logger_Access_ErrorCases(t *testing.T) {
data = logRecordFromBuffer(b)
a.Equal("error", data.Level)
a.Equal("oops", data.Error)
a.Equal("ERROR GET /foo", data.Message)
a.Equal("ERROR ->GET /foo", data.Message)
}

func Test_Logger_Application(t *testing.T) {
Expand Down

0 comments on commit f39349c

Please sign in to comment.