log: use log.Print instead of fmt.Print

This commit is contained in:
Alex Crawford 2015-05-14 17:31:57 -07:00
parent fac805dc11
commit 81ffa056bd
5 changed files with 22 additions and 21 deletions

View File

@ -17,6 +17,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"sync" "sync"
"time" "time"
@ -160,37 +161,37 @@ func main() {
ds := selectDatasource(dss) ds := selectDatasource(dss)
if ds == nil { if ds == nil {
fmt.Println("No datasources available in time") log.Println("No datasources available in time")
os.Exit(1) 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() userdataBytes, err := ds.FetchUserdata()
if err != nil { 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 failure = true
} }
if report, err := validate.Validate(userdataBytes); err == nil { if report, err := validate.Validate(userdataBytes); err == nil {
ret := 0 ret := 0
for _, e := range report.Entries() { for _, e := range report.Entries() {
fmt.Println(e) log.Println(e)
ret = 1 ret = 1
} }
if flags.validate { if flags.validate {
os.Exit(ret) os.Exit(ret)
} }
} else { } else {
fmt.Printf("Failed while validating user_data (%q)\n", err) log.Printf("Failed while validating user_data (%q)\n", err)
if flags.validate { if flags.validate {
os.Exit(1) 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() metadata, err := ds.FetchMetadata()
if err != nil { 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) os.Exit(1)
} }
@ -216,7 +217,7 @@ func main() {
failure = true 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) cc := mergeConfigs(ccu, metadata)
var ifaces []network.InterfaceGenerator var ifaces []network.InterfaceGenerator
@ -233,19 +234,19 @@ func main() {
err = fmt.Errorf("Unsupported network config format %q", flags.convertNetconf) err = fmt.Errorf("Unsupported network config format %q", flags.convertNetconf)
} }
if err != nil { if err != nil {
fmt.Printf("Failed to generate interfaces: %v\n", err) log.Printf("Failed to generate interfaces: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }
if err = initialize.Apply(cc, ifaces, env); err != nil { 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) os.Exit(1)
} }
if script != nil { if script != nil {
if err = runScript(*script, env); err != 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) os.Exit(1)
} }
} }
@ -265,7 +266,7 @@ func mergeConfigs(cc *config.CloudConfig, md datasource.Metadata) (out config.Cl
if md.Hostname != "" { if md.Hostname != "" {
if out.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 { } else {
out.Hostname = md.Hostname out.Hostname = md.Hostname
} }
@ -330,7 +331,7 @@ func selectDatasource(sources []datasource.Datasource) datasource.Datasource {
duration := datasourceInterval duration := datasourceInterval
for { for {
fmt.Printf("Checking availability of %q\n", s.Type()) log.Printf("Checking availability of %q\n", s.Type())
if s.IsAvailable() { if s.IsAvailable() {
ds <- s ds <- s
return return
@ -368,7 +369,7 @@ func selectDatasource(sources []datasource.Datasource) datasource.Datasource {
func runScript(script config.Script, env *initialize.Environment) error { func runScript(script config.Script, env *initialize.Environment) error {
err := initialize.PrepWorkspace(env.Workspace()) err := initialize.PrepWorkspace(env.Workspace())
if err != nil { if err != nil {
fmt.Printf("Failed preparing workspace: %v\n", err) log.Printf("Failed preparing workspace: %v\n", err)
return err return err
} }
path, err := initialize.PersistScriptInWorkspace(script, env.Workspace()) path, err := initialize.PersistScriptInWorkspace(script, env.Workspace())

View File

@ -16,8 +16,8 @@ package configdrive
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path" "path"
@ -93,7 +93,7 @@ func (cd *configDrive) openstackVersionRoot() string {
} }
func (cd *configDrive) tryReadFile(filename string) ([]byte, error) { 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) data, err := cd.readFile(filename)
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = nil err = nil

View File

@ -18,6 +18,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"log"
"net" "net"
"strings" "strings"
@ -61,7 +62,7 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) {
return metadata, err return metadata, err
} }
metadata.SSHPublicKeys[name] = sshkey 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 { } else if _, ok := err.(pkg.ErrNotFound); !ok {
return metadata, err return metadata, err

View File

@ -16,8 +16,8 @@ package waagent
import ( import (
"encoding/xml" "encoding/xml"
"fmt"
"io/ioutil" "io/ioutil"
"log"
"net" "net"
"os" "os"
"path" "path"
@ -108,7 +108,7 @@ func (a *waagent) Type() string {
} }
func (a *waagent) tryReadFile(filename string) ([]byte, error) { 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) data, err := a.readFile(filename)
if os.IsNotExist(err) { if os.IsNotExist(err) {
err = nil err = nil

View File

@ -15,7 +15,6 @@
package system package system
import ( import (
"fmt"
"log" "log"
"net" "net"
"os/exec" "os/exec"
@ -59,7 +58,7 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error {
if systemInterface, ok := sysInterfaceMap[iface.Name()]; ok { if systemInterface, ok := sysInterfaceMap[iface.Name()]; ok {
log.Printf("Taking down interface %q\n", systemInterface.Name) log.Printf("Taking down interface %q\n", systemInterface.Name)
if err := netlink.NetworkLinkDown(systemInterface); err != nil { 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)
} }
} }
} }