diff --git a/go.mod b/go.mod index 54624a4..e2ab527 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/docker/docker v1.13.1 github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect + github.com/gorilla/handlers v1.4.2 github.com/opencontainers/go-digest v1.0.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/sirupsen/logrus v1.6.0 diff --git a/go.sum b/go.sum index 802a964..71947e6 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg= +github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index d1d29b5..13a63a8 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -2,15 +2,25 @@ package plugin import ( "fmt" + "io" "net" "net/http" docker "github.com/docker/docker/client" + "github.com/gorilla/handlers" + log "github.com/sirupsen/logrus" ) // DriverName is the name of the Docker Network Driver const DriverName string = "net-dhcp" +func writeAccessLog(w io.Writer, params handlers.LogFormatterParams) { + log.WithFields(log.Fields{ + "status": params.StatusCode, + "resSize": params.Size, + }).Debugf("%v %v", params.Request.Method, params.URL.RequestURI()) +} + // Plugin is the DHCP network plugin type Plugin struct { docker *docker.Client @@ -30,11 +40,12 @@ func NewPlugin() (*Plugin, error) { mux := http.NewServeMux() mux.HandleFunc("/NetworkDriver.GetCapabilities", p.apiGetCapabilities) + mux.HandleFunc("/NetworkDriver.CreateNetwork", p.apiCreateNetwork) mux.HandleFunc("/NetworkDriver.DeleteNetwork", p.apiDeleteNetwork) p.server = http.Server{ - Handler: mux, + Handler: handlers.CustomLoggingHandler(nil, mux, writeAccessLog), } return &p, nil