From d536fe9027c01aea2899be14d29d587497a41873 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 11 Dec 2015 15:02:13 -0800 Subject: [PATCH] Remove all calls to the default logger --- client/driver/docker.go | 26 +++++++++++++------------- client/fingerprint/env_aws.go | 8 ++++---- command/agent/command_test.go | 3 +-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 25c6874fb75b..330acd75c978 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -455,27 +455,27 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle }, }) if err != nil { - log.Printf("[ERR] driver.docker: failed to query list of containers matching name:%s", config.Name) + d.logger.Printf("[ERR] driver.docker: failed to query list of containers matching name:%s", config.Name) return nil, fmt.Errorf("Failed to query list of containers: %s", err) } if len(containers) != 1 { - log.Printf("[ERR] driver.docker: failed to get id for container %s", config.Name) + d.logger.Printf("[ERR] driver.docker: failed to get id for container %s", config.Name) return nil, fmt.Errorf("Failed to get id for container %s", config.Name) } - log.Printf("[INFO] driver.docker: a container with the name %s already exists; will attempt to purge and re-create", config.Name) + d.logger.Printf("[INFO] driver.docker: a container with the name %s already exists; will attempt to purge and re-create", config.Name) err = client.RemoveContainer(docker.RemoveContainerOptions{ ID: containers[0].ID, }) if err != nil { - log.Printf("[ERR] driver.docker: failed to purge container %s", config.Name) + d.logger.Printf("[ERR] driver.docker: failed to purge container %s", config.Name) return nil, fmt.Errorf("Failed to purge container %s: %s", config.Name, err) } - log.Printf("[INFO] driver.docker: purged container %s", config.Name) + d.logger.Printf("[INFO] driver.docker: purged container %s", config.Name) container, err = client.CreateContainer(config) if err != nil { - log.Printf("[ERR] driver.docker: failed to re-create container %s; aborting", config.Name) + d.logger.Printf("[ERR] driver.docker: failed to re-create container %s; aborting", config.Name) return nil, fmt.Errorf("Failed to re-create container %s; aborting", config.Name) } } else { @@ -593,10 +593,10 @@ func (h *DockerHandle) Kill() error { // Stop the container err := h.client.StopContainer(h.containerID, 5) if err != nil { - log.Printf("[ERR] driver.docker: failed to stop container %s", h.containerID) + h.logger.Printf("[ERR] driver.docker: failed to stop container %s", h.containerID) return fmt.Errorf("Failed to stop container %s: %s", h.containerID, err) } - log.Printf("[INFO] driver.docker: stopped container %s", h.containerID) + h.logger.Printf("[INFO] driver.docker: stopped container %s", h.containerID) // Cleanup container if h.cleanupContainer { @@ -605,10 +605,10 @@ func (h *DockerHandle) Kill() error { RemoveVolumes: true, }) if err != nil { - log.Printf("[ERR] driver.docker: failed to remove container %s", h.containerID) + h.logger.Printf("[ERR] driver.docker: failed to remove container %s", h.containerID) return fmt.Errorf("Failed to remove container %s: %s", h.containerID, err) } - log.Printf("[INFO] driver.docker: removed container %s", h.containerID) + h.logger.Printf("[INFO] driver.docker: removed container %s", h.containerID) } // Cleanup image. This operation may fail if the image is in use by another @@ -624,17 +624,17 @@ func (h *DockerHandle) Kill() error { }, }) if err != nil { - log.Printf("[ERR] driver.docker: failed to query list of containers matching image:%s", h.imageID) + h.logger.Printf("[ERR] driver.docker: failed to query list of containers matching image:%s", h.imageID) return fmt.Errorf("Failed to query list of containers: %s", err) } inUse := len(containers) if inUse > 0 { - log.Printf("[INFO] driver.docker: image %s is still in use by %d container(s)", h.imageID, inUse) + h.logger.Printf("[INFO] driver.docker: image %s is still in use by %d container(s)", h.imageID, inUse) } else { return fmt.Errorf("Failed to remove image %s", h.imageID) } } else { - log.Printf("[INFO] driver.docker: removed image %s", h.imageID) + h.logger.Printf("[INFO] driver.docker: removed image %s", h.imageID) } } return nil diff --git a/client/fingerprint/env_aws.go b/client/fingerprint/env_aws.go index ca50a76c3da2..1963f6c50aff 100644 --- a/client/fingerprint/env_aws.go +++ b/client/fingerprint/env_aws.go @@ -80,7 +80,7 @@ func NewEnvAWSFingerprint(logger *log.Logger) Fingerprint { } func (f *EnvAWSFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) (bool, error) { - if !isAWS() { + if !f.isAWS() { return false, nil } @@ -161,7 +161,7 @@ func (f *EnvAWSFingerprint) Fingerprint(cfg *config.Config, node *structs.Node) return true, nil } -func isAWS() bool { +func (f *EnvAWSFingerprint) isAWS() bool { // Read the internal metadata URL from the environment, allowing test files to // provide their own metadataURL := os.Getenv("AWS_ENV_URL") @@ -178,7 +178,7 @@ func isAWS() bool { // Query the metadata url for the ami-id, to veryify we're on AWS resp, err := client.Get(metadataURL + "ami-id") if err != nil { - log.Printf("[DEBUG] fingerprint.env_aws: Error querying AWS Metadata URL, skipping") + f.logger.Printf("[DEBUG] fingerprint.env_aws: Error querying AWS Metadata URL, skipping") return false } defer resp.Body.Close() @@ -190,7 +190,7 @@ func isAWS() bool { instanceID, err := ioutil.ReadAll(resp.Body) if err != nil { - log.Printf("[DEBUG] fingerprint.env_aws: Error reading AWS Instance ID, skipping") + f.logger.Printf("[DEBUG] fingerprint.env_aws: Error reading AWS Instance ID, skipping") return false } diff --git a/command/agent/command_test.go b/command/agent/command_test.go index a4226185334b..9e6d750ef5fa 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -3,7 +3,6 @@ package agent import ( "fmt" "io/ioutil" - "log" "os" "strings" "testing" @@ -112,7 +111,7 @@ func TestRetryJoin(t *testing.T) { go func() { if code := cmd.Run(args); code != 0 { - log.Printf("bad: %d", code) + t.Logf("bad: %d", code) } close(doneCh) }()