Skip to content

Commit

Permalink
feat: use log instead of fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyoucao577 committed Oct 7, 2019
1 parent 2aa3157 commit 389796c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/diagnosis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
16 changes: 8 additions & 8 deletions diagnosis/fetching.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package diagnosis

import (
"fmt"
"log"
"net"
"os"

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions diagnosis/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package diagnosis

import (
"encoding/json"
"fmt"
"log"
)

// Info includes information for diagnosis.
Expand All @@ -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)
Expand Down

0 comments on commit 389796c

Please sign in to comment.