Extract log utils into pkg/log

Docker-DCO-1.1-Signed-off-by: Josiah Kiehl <josiah@capoferro.net> (github: capoferro)
This commit is contained in:
Josiah Kiehl 2014-07-24 13:37:44 -07:00 committed by Erik Hollensbe
parent 7ef3a5bc73
commit 2a7cf96c8f
2 changed files with 12 additions and 9 deletions

View file

@ -15,6 +15,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/utils" "github.com/docker/docker/utils"
) )
@ -186,17 +187,17 @@ func pingRegistryEndpoint(endpoint string) (RegistryInfo, error) {
Standalone: true, Standalone: true,
} }
if err := json.Unmarshal(jsonString, &info); err != nil { if err := json.Unmarshal(jsonString, &info); err != nil {
utils.Debugf("Error unmarshalling the _ping RegistryInfo: %s", err) log.Debugf("Error unmarshalling the _ping RegistryInfo: %s", err)
// don't stop here. Just assume sane defaults // don't stop here. Just assume sane defaults
} }
if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" { if hdr := resp.Header.Get("X-Docker-Registry-Version"); hdr != "" {
utils.Debugf("Registry version header: '%s'", hdr) log.Debugf("Registry version header: '%s'", hdr)
info.Version = hdr info.Version = hdr
} }
utils.Debugf("RegistryInfo.Version: %q", info.Version) log.Debugf("RegistryInfo.Version: %q", info.Version)
standalone := resp.Header.Get("X-Docker-Registry-Standalone") standalone := resp.Header.Get("X-Docker-Registry-Standalone")
utils.Debugf("Registry standalone header: '%s'", standalone) log.Debugf("Registry standalone header: '%s'", standalone)
// Accepted values are "true" (case-insensitive) and "1". // Accepted values are "true" (case-insensitive) and "1".
if strings.EqualFold(standalone, "true") || standalone == "1" { if strings.EqualFold(standalone, "true") || standalone == "1" {
info.Standalone = true info.Standalone = true
@ -204,7 +205,7 @@ func pingRegistryEndpoint(endpoint string) (RegistryInfo, error) {
// there is a header set, and it is not "true" or "1", so assume fails // there is a header set, and it is not "true" or "1", so assume fails
info.Standalone = false info.Standalone = false
} }
utils.Debugf("RegistryInfo.Standalone: %q", info.Standalone) log.Debugf("RegistryInfo.Standalone: %q", info.Standalone)
return info, nil return info, nil
} }
@ -274,7 +275,7 @@ func ExpandAndVerifyRegistryUrl(hostname string) (string, error) {
} }
endpoint := fmt.Sprintf("https://%s/v1/", hostname) endpoint := fmt.Sprintf("https://%s/v1/", hostname)
if _, err := pingRegistryEndpoint(endpoint); err != nil { if _, err := pingRegistryEndpoint(endpoint); err != nil {
utils.Debugf("Registry %s does not work (%s), falling back to http", endpoint, err) log.Debugf("Registry %s does not work (%s), falling back to http", endpoint, err)
endpoint = fmt.Sprintf("http://%s/v1/", hostname) endpoint = fmt.Sprintf("http://%s/v1/", hostname)
if _, err = pingRegistryEndpoint(endpoint); err != nil { if _, err = pingRegistryEndpoint(endpoint); err != nil {
//TODO: triggering highland build can be done there without "failing" //TODO: triggering highland build can be done there without "failing"

View file

@ -3,8 +3,6 @@ package registry
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/docker/docker/utils"
"github.com/gorilla/mux"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -14,6 +12,10 @@ import (
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/gorilla/mux"
"github.com/docker/docker/pkg/log"
) )
var ( var (
@ -96,7 +98,7 @@ func init() {
func handlerAccessLog(handler http.Handler) http.Handler { func handlerAccessLog(handler http.Handler) http.Handler {
logHandler := func(w http.ResponseWriter, r *http.Request) { logHandler := func(w http.ResponseWriter, r *http.Request) {
utils.Debugf("%s \"%s %s\"", r.RemoteAddr, r.Method, r.URL) log.Debugf("%s \"%s %s\"", r.RemoteAddr, r.Method, r.URL)
handler.ServeHTTP(w, r) handler.ServeHTTP(w, r)
} }
return http.HandlerFunc(logHandler) return http.HandlerFunc(logHandler)