mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
add log
This commit is contained in:
parent
72292a4412
commit
9453b06b1c
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bitly/go-simplejson"
|
"github.com/bitly/go-simplejson"
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -17,6 +18,7 @@ func get_currentIP(url string) (string, error) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Cannot get IP...")
|
fmt.Println("Cannot get IP...")
|
||||||
|
log.Error("Cannot get IP...")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
godns.go
12
godns.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -11,8 +12,10 @@ var Configuration Settings
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Starting...")
|
fmt.Println("Starting...")
|
||||||
|
log.Info("Starting...")
|
||||||
|
|
||||||
Configuration = LoadSettings()
|
Configuration = LoadSettings()
|
||||||
|
initLog()
|
||||||
|
|
||||||
loop := make(chan bool)
|
loop := make(chan bool)
|
||||||
go dns_loop(loop)
|
go dns_loop(loop)
|
||||||
@ -21,6 +24,7 @@ func main() {
|
|||||||
|
|
||||||
if !ret {
|
if !ret {
|
||||||
fmt.Println("Dns loop exited...")
|
fmt.Println("Dns loop exited...")
|
||||||
|
log.Error("Dns loop exited...")
|
||||||
close(loop)
|
close(loop)
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -33,19 +37,27 @@ func dns_loop(loop chan bool) {
|
|||||||
|
|
||||||
domain_id := get_domain(Configuration.Domain)
|
domain_id := get_domain(Configuration.Domain)
|
||||||
|
|
||||||
|
if domain_id == -1 {
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
currentIP, _ := get_currentIP(Configuration.IP_Url)
|
currentIP, _ := get_currentIP(Configuration.IP_Url)
|
||||||
sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain)
|
sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain)
|
||||||
|
|
||||||
fmt.Printf("currentIp is:%s\n", currentIP)
|
fmt.Printf("currentIp is:%s\n", currentIP)
|
||||||
|
log.Infof("currentIp is:%s\n", currentIP)
|
||||||
|
|
||||||
//Continue to check the IP of sub-domain
|
//Continue to check the IP of sub-domain
|
||||||
if len(ip) > 0 && !strings.Contains(currentIP, ip) {
|
if len(ip) > 0 && !strings.Contains(currentIP, ip) {
|
||||||
|
|
||||||
fmt.Println("Start to update record 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)
|
update_ip(domain_id, sub_domain_id, Configuration.Sub_domain, currentIP)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Current IP is same as domain IP, no need to update...")
|
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
|
//Interval is 5 minutes
|
||||||
|
15
logger.go
Normal file
15
logger.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import log "github.com/cihub/seelog"
|
||||||
|
|
||||||
|
func initLog() {
|
||||||
|
testConfig := `
|
||||||
|
<seelog>
|
||||||
|
<outputs>
|
||||||
|
<rollingfile type="size" filename="run.log" maxsize="100" maxrolls="5" />
|
||||||
|
</outputs>
|
||||||
|
</seelog>
|
||||||
|
`
|
||||||
|
logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
|
||||||
|
log.ReplaceLogger(logger)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user