diff --git a/dns_handler.go b/dns_handler.go index 7f07f9a..95cf00b 100644 --- a/dns_handler.go +++ b/dns_handler.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "github.com/bitly/go-simplejson" + log "github.com/cihub/seelog" "io/ioutil" "net/http" "net/url" @@ -17,6 +18,7 @@ func get_currentIP(url string) (string, error) { if err != nil { fmt.Println("Cannot get IP...") + log.Error("Cannot get IP...") return "", err } diff --git a/godns.go b/godns.go index 0f8b2ce..9577d4a 100644 --- a/godns.go +++ b/godns.go @@ -2,6 +2,7 @@ package main import ( "fmt" + log "github.com/cihub/seelog" "os" "strings" "time" @@ -11,8 +12,10 @@ var Configuration Settings func main() { fmt.Println("Starting...") + log.Info("Starting...") Configuration = LoadSettings() + initLog() loop := make(chan bool) go dns_loop(loop) @@ -21,6 +24,7 @@ func main() { if !ret { fmt.Println("Dns loop exited...") + log.Error("Dns loop exited...") close(loop) os.Exit(1) @@ -33,19 +37,27 @@ func dns_loop(loop chan bool) { domain_id := get_domain(Configuration.Domain) + if domain_id == -1 { + + continue + } + currentIP, _ := get_currentIP(Configuration.IP_Url) sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain) fmt.Printf("currentIp is:%s\n", currentIP) + log.Infof("currentIp is:%s\n", currentIP) //Continue to check the IP of sub-domain if len(ip) > 0 && !strings.Contains(currentIP, ip) { fmt.Println("Start to update record IP...") + log.Info("Start to update record IP...") update_ip(domain_id, sub_domain_id, Configuration.Sub_domain, currentIP) } else { fmt.Println("Current IP is same as domain IP, no need to update...") + log.Info("Current IP is same as domain IP, no need to update...") } //Interval is 5 minutes diff --git a/logger.go b/logger.go new file mode 100644 index 0000000..b135c1d --- /dev/null +++ b/logger.go @@ -0,0 +1,15 @@ +package main + +import log "github.com/cihub/seelog" + +func initLog() { + testConfig := ` + + + + + +` + logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig)) + log.ReplaceLogger(logger) +}