First stage of access logging middleware. Initially without any output appenders.

This commit is contained in:
Richard Shepherd 2017-04-10 08:51:08 +01:00 committed by Timo Reimann
parent 4310bdf3ca
commit 73a1b172ed
9 changed files with 447 additions and 34 deletions

View file

@ -1,6 +1,7 @@
package middlewares
import (
"context"
"fmt"
"io/ioutil"
"net/http"
@ -10,6 +11,7 @@ import (
"runtime"
"testing"
"github.com/containous/traefik/middlewares/accesslog"
shellwords "github.com/mattn/go-shellwords"
"github.com/stretchr/testify/assert"
)
@ -64,7 +66,15 @@ func TestLogger(t *testing.T) {
},
}
logger.ServeHTTP(&logtestResponseWriter{}, r, LogWriterTestHandlerFunc)
// Temporary - until new access logger is fully implemented
// create the data table and populate frontend and backend
core := make(accesslog.CoreLogData)
logDataTable := &accesslog.LogData{Core: core, Request: r.Header}
logDataTable.Core[accesslog.FrontendName] = testFrontendName
logDataTable.Core[accesslog.BackendURL] = testBackendName
req := r.WithContext(context.WithValue(r.Context(), accesslog.DataTableKey, logDataTable))
logger.ServeHTTP(&logtestResponseWriter{}, req, LogWriterTestHandlerFunc)
if logdata, err := ioutil.ReadFile(logfilePath); err != nil {
fmt.Printf("%s\n%s\n", string(logdata), err.Error())