Minor refactor as requested in PR comments
This commit is contained in:
parent
8bac454792
commit
bf1f6f663a
4 changed files with 27 additions and 37 deletions
0
examples/k8s.namespace.sh
Normal file → Executable file
0
examples/k8s.namespace.sh
Normal file → Executable file
|
@ -37,9 +37,9 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
|
|||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
// Verify Traefik started OK
|
||||
if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil {
|
||||
c.Assert(err.Error(), checker.Equals, "")
|
||||
} else if len(traefikLog) > 0 {
|
||||
traefikLog, err := ioutil.ReadFile("traefik.log")
|
||||
c.Assert(err, checker.IsNil)
|
||||
if len(traefikLog) > 0 {
|
||||
fmt.Printf("%s\n", string(traefikLog))
|
||||
c.Assert(len(traefikLog), checker.Equals, 0)
|
||||
}
|
||||
|
@ -61,33 +61,29 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// Verify access.log output as expected
|
||||
if accessLog, err := ioutil.ReadFile("access.log"); err != nil {
|
||||
c.Assert(err.Error(), checker.Equals, "")
|
||||
} else {
|
||||
lines := strings.Split(string(accessLog), "\n")
|
||||
count := 0
|
||||
for i, line := range lines {
|
||||
if len(line) > 0 {
|
||||
count++
|
||||
if tokens, err := shellwords.Parse(line); err != nil {
|
||||
c.Assert(err.Error(), checker.Equals, "")
|
||||
} else {
|
||||
c.Assert(len(tokens), checker.Equals, 13)
|
||||
c.Assert(tokens[6], checker.Equals, "200")
|
||||
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[11], "http://127.0.0.1:808"), checker.True)
|
||||
c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True)
|
||||
}
|
||||
}
|
||||
accessLog, err := ioutil.ReadFile("access.log")
|
||||
c.Assert(err, checker.IsNil)
|
||||
lines := strings.Split(string(accessLog), "\n")
|
||||
count := 0
|
||||
for i, line := range lines {
|
||||
if len(line) > 0 {
|
||||
count++
|
||||
tokens, err := shellwords.Parse(line)
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(len(tokens), checker.Equals, 13)
|
||||
c.Assert(tokens[6], checker.Equals, "200")
|
||||
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[11], "http://127.0.0.1:808"), checker.True)
|
||||
c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True)
|
||||
}
|
||||
c.Assert(count, checker.Equals, 3)
|
||||
}
|
||||
c.Assert(count, checker.Equals, 3)
|
||||
|
||||
// Verify no other Traefik problems
|
||||
if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil {
|
||||
c.Assert(err.Error(), checker.Equals, "")
|
||||
} else if len(traefikLog) > 0 {
|
||||
traefikLog, err = ioutil.ReadFile("traefik.log")
|
||||
c.Assert(err, checker.IsNil)
|
||||
if len(traefikLog) > 0 {
|
||||
fmt.Printf("%s\n", string(traefikLog))
|
||||
c.Assert(len(traefikLog), checker.Equals, 0)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package middlewares
|
||||
|
||||
/*
|
||||
Middleware Logger writes each request and its response to the access log.
|
||||
It gets some information from the logInfoResponseWriter set up by previous middleware.
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
@ -23,7 +18,10 @@ const (
|
|||
loggerReqidHeader = "X-Traefik-Reqid"
|
||||
)
|
||||
|
||||
// Logger holds the File defining the access log
|
||||
/*
|
||||
Middleware Logger writes each request and its response to the access log.
|
||||
It gets some information from the logInfoResponseWriter set up by previous middleware.
|
||||
*/
|
||||
type Logger struct {
|
||||
file *os.File
|
||||
}
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package middlewares
|
||||
|
||||
/*
|
||||
Middleware saveBackend sends the backend name to the logger.
|
||||
*/
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// SaveBackend holds the next handler
|
||||
// Middleware saveBackend sends the backend name to the logger.
|
||||
type SaveBackend struct {
|
||||
next http.Handler
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue