From 81ffa056bdd8a8d33274f4886ba7a93239a5ab5f Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Thu, 14 May 2015 17:31:57 -0700 Subject: [PATCH] log: use log.Print instead of fmt.Print --- coreos-cloudinit.go | 29 ++++++++++++++------------- datasource/configdrive/configdrive.go | 4 ++-- datasource/metadata/ec2/metadata.go | 3 ++- datasource/waagent/waagent.go | 4 ++-- system/networkd.go | 3 +-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index 4137d7e..c8ed1ee 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -17,6 +17,7 @@ package main import ( "flag" "fmt" + "log" "os" "sync" "time" @@ -160,37 +161,37 @@ func main() { ds := selectDatasource(dss) if ds == nil { - fmt.Println("No datasources available in time") + log.Println("No datasources available in time") os.Exit(1) } - fmt.Printf("Fetching user-data from datasource of type %q\n", ds.Type()) + log.Printf("Fetching user-data from datasource of type %q\n", ds.Type()) userdataBytes, err := ds.FetchUserdata() if err != nil { - fmt.Printf("Failed fetching user-data from datasource: %v\nContinuing...\n", err) + log.Printf("Failed fetching user-data from datasource: %v. Continuing...\n", err) failure = true } if report, err := validate.Validate(userdataBytes); err == nil { ret := 0 for _, e := range report.Entries() { - fmt.Println(e) + log.Println(e) ret = 1 } if flags.validate { os.Exit(ret) } } else { - fmt.Printf("Failed while validating user_data (%q)\n", err) + log.Printf("Failed while validating user_data (%q)\n", err) if flags.validate { os.Exit(1) } } - fmt.Printf("Fetching meta-data from datasource of type %q\n", ds.Type()) + log.Printf("Fetching meta-data from datasource of type %q\n", ds.Type()) metadata, err := ds.FetchMetadata() if err != nil { - fmt.Printf("Failed fetching meta-data from datasource: %v\n", err) + log.Printf("Failed fetching meta-data from datasource: %v\n", err) os.Exit(1) } @@ -216,7 +217,7 @@ func main() { failure = true } - fmt.Println("Merging cloud-config from meta-data and user-data") + log.Println("Merging cloud-config from meta-data and user-data") cc := mergeConfigs(ccu, metadata) var ifaces []network.InterfaceGenerator @@ -233,19 +234,19 @@ func main() { err = fmt.Errorf("Unsupported network config format %q", flags.convertNetconf) } if err != nil { - fmt.Printf("Failed to generate interfaces: %v\n", err) + log.Printf("Failed to generate interfaces: %v\n", err) os.Exit(1) } } if err = initialize.Apply(cc, ifaces, env); err != nil { - fmt.Printf("Failed to apply cloud-config: %v\n", err) + log.Printf("Failed to apply cloud-config: %v\n", err) os.Exit(1) } if script != nil { if err = runScript(*script, env); err != nil { - fmt.Printf("Failed to run script: %v\n", err) + log.Printf("Failed to run script: %v\n", err) os.Exit(1) } } @@ -265,7 +266,7 @@ func mergeConfigs(cc *config.CloudConfig, md datasource.Metadata) (out config.Cl if md.Hostname != "" { if out.Hostname != "" { - fmt.Printf("Warning: user-data hostname (%s) overrides metadata hostname (%s)\n", out.Hostname, md.Hostname) + log.Printf("Warning: user-data hostname (%s) overrides metadata hostname (%s)\n", out.Hostname, md.Hostname) } else { out.Hostname = md.Hostname } @@ -330,7 +331,7 @@ func selectDatasource(sources []datasource.Datasource) datasource.Datasource { duration := datasourceInterval for { - fmt.Printf("Checking availability of %q\n", s.Type()) + log.Printf("Checking availability of %q\n", s.Type()) if s.IsAvailable() { ds <- s return @@ -368,7 +369,7 @@ func selectDatasource(sources []datasource.Datasource) datasource.Datasource { func runScript(script config.Script, env *initialize.Environment) error { err := initialize.PrepWorkspace(env.Workspace()) if err != nil { - fmt.Printf("Failed preparing workspace: %v\n", err) + log.Printf("Failed preparing workspace: %v\n", err) return err } path, err := initialize.PersistScriptInWorkspace(script, env.Workspace()) diff --git a/datasource/configdrive/configdrive.go b/datasource/configdrive/configdrive.go index ed4c7c7..6c65bfc 100644 --- a/datasource/configdrive/configdrive.go +++ b/datasource/configdrive/configdrive.go @@ -16,8 +16,8 @@ package configdrive import ( "encoding/json" - "fmt" "io/ioutil" + "log" "os" "path" @@ -93,7 +93,7 @@ func (cd *configDrive) openstackVersionRoot() string { } func (cd *configDrive) tryReadFile(filename string) ([]byte, error) { - fmt.Printf("Attempting to read from %q\n", filename) + log.Printf("Attempting to read from %q\n", filename) data, err := cd.readFile(filename) if os.IsNotExist(err) { err = nil diff --git a/datasource/metadata/ec2/metadata.go b/datasource/metadata/ec2/metadata.go index 35baa09..141fdc9 100644 --- a/datasource/metadata/ec2/metadata.go +++ b/datasource/metadata/ec2/metadata.go @@ -18,6 +18,7 @@ import ( "bufio" "bytes" "fmt" + "log" "net" "strings" @@ -61,7 +62,7 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) { return metadata, err } metadata.SSHPublicKeys[name] = sshkey - fmt.Printf("Found SSH key for %q\n", name) + log.Printf("Found SSH key for %q\n", name) } } else if _, ok := err.(pkg.ErrNotFound); !ok { return metadata, err diff --git a/datasource/waagent/waagent.go b/datasource/waagent/waagent.go index d0460b9..c70a60f 100644 --- a/datasource/waagent/waagent.go +++ b/datasource/waagent/waagent.go @@ -16,8 +16,8 @@ package waagent import ( "encoding/xml" - "fmt" "io/ioutil" + "log" "net" "os" "path" @@ -108,7 +108,7 @@ func (a *waagent) Type() string { } func (a *waagent) tryReadFile(filename string) ([]byte, error) { - fmt.Printf("Attempting to read from %q\n", filename) + log.Printf("Attempting to read from %q\n", filename) data, err := a.readFile(filename) if os.IsNotExist(err) { err = nil diff --git a/system/networkd.go b/system/networkd.go index c9e06ab..2b33af2 100644 --- a/system/networkd.go +++ b/system/networkd.go @@ -15,7 +15,6 @@ package system import ( - "fmt" "log" "net" "os/exec" @@ -59,7 +58,7 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error { if systemInterface, ok := sysInterfaceMap[iface.Name()]; ok { log.Printf("Taking down interface %q\n", systemInterface.Name) if err := netlink.NetworkLinkDown(systemInterface); err != nil { - fmt.Printf("Error while downing interface %q (%s). Continuing...\n", systemInterface.Name, err) + log.Printf("Error while downing interface %q (%s). Continuing...\n", systemInterface.Name, err) } } }