diff --git a/cmd/diagnosis/main.go b/cmd/diagnosis/main.go index 616ae15..4d0dad2 100644 --- a/cmd/diagnosis/main.go +++ b/cmd/diagnosis/main.go @@ -9,6 +9,8 @@ import ( ) func main() { + //log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Llongfile) + log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile) mux := http.NewServeMux() diff --git a/diagnosis/fetching.go b/diagnosis/fetching.go index d76830f..b2763f1 100644 --- a/diagnosis/fetching.go +++ b/diagnosis/fetching.go @@ -1,7 +1,7 @@ package diagnosis import ( - "fmt" + "log" "net" "os" @@ -15,37 +15,37 @@ func New() *Info { //hostname hostname, err := os.Hostname() if err != nil { - fmt.Printf("get hostname failed, err %v\n", err) + log.Printf("get hostname failed, err %v\n", err) } else { - fmt.Printf("Hostname: %s\n", hostname) + log.Printf("Hostname: %s\n", hostname) info.Hostname = hostname } //ip addresses addrs, err := net.InterfaceAddrs() if err != nil { - fmt.Printf("lookup network interface addrs failed, err %v\n", err) + log.Printf("lookup network interface addrs failed, err %v\n", err) } else { for _, addr := range addrs { ip, _, err := net.ParseCIDR(addr.String()) if err != nil { - fmt.Printf("ParseCIDR addrs failed, err %v\n", err) + log.Printf("ParseCIDR addrs failed, err %v\n", err) continue } if ip.IsLoopback() { - fmt.Printf("ignore Loopback ip address-->%s\n", addr.String()) + log.Printf("ignore Loopback ip address-->%s\n", addr.String()) continue } - fmt.Printf("%s ip address-->%s\n", addr.Network(), addr.String()) + log.Printf("%s ip address-->%s\n", addr.Network(), addr.String()) info.IPAddresses = append(info.IPAddresses, addr.String()) } } //from goInfo gi := goInfo.GetInfo() - gi.VarDump() + log.Println(gi) info.CPUs = gi.CPUs return &info diff --git a/diagnosis/info.go b/diagnosis/info.go index f0b2a16..81c50ec 100644 --- a/diagnosis/info.go +++ b/diagnosis/info.go @@ -2,7 +2,7 @@ package diagnosis import ( "encoding/json" - "fmt" + "log" ) // Info includes information for diagnosis. @@ -19,7 +19,7 @@ type Info struct { func (info Info) String() string { jsonstr, err := json.Marshal(info) if err != nil { - fmt.Printf("to json failed, err %v\n", err) + log.Fatalf("to json failed, err %v\n", err) return err.Error() } return string(jsonstr)