summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-03 19:33:13 -0600
committerJeff Carr <[email protected]>2024-01-03 19:33:13 -0600
commitc1a00fcc1a4cb67d8ba8ae97e90ceed95f73872d (patch)
treeb16ea631c3f8235a3d1bd2ce5b0109a939a735c5
parent138f72728cbbd10ea3d64888a6482d4c1a21718e (diff)
use 'go.wit.com/log'
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--args.go23
-rw-r--r--bash.go7
-rw-r--r--dns.go12
-rw-r--r--fsnotify.go6
-rw-r--r--gui.go45
-rw-r--r--hostname.go28
-rw-r--r--hostnameStatus.go2
-rw-r--r--log.go59
-rw-r--r--main.go28
-rw-r--r--net.go10
-rw-r--r--nsupdate.go8
-rw-r--r--proc.go28
-rw-r--r--rtnetlink.go4
-rw-r--r--unix.go10
14 files changed, 115 insertions, 155 deletions
diff --git a/args.go b/args.go
index 39a2ee6..ba6ee85 100644
--- a/args.go
+++ b/args.go
@@ -19,24 +19,45 @@ var args struct {
}
var NET log.LogFlag
+var NOW log.LogFlag
+var PROC log.LogFlag
var SPEW log.LogFlag
+var CHANGE log.LogFlag
func init() {
arg.MustParse(&args)
// fmt.Println(args.Foo, args.Bar, args.User)
+ NOW.B = false
+ NOW.Name = "NOW"
+ NOW.Subsystem = "cpdns"
+ NOW.Desc = "temp debugging stuff"
+ NOW.Register()
+
NET.B = false
NET.Name = "NET"
NET.Subsystem = "cpdns"
NET.Desc = "Network logging"
NET.Register()
+ PROC.B = false
+ PROC.Name = "PROC"
+ PROC.Subsystem = "cpdns"
+ PROC.Desc = "/proc logging"
+ PROC.Register()
+
SPEW.B = false
SPEW.Name = "SPEW"
SPEW.Subsystem = "cpdns"
SPEW.Desc = "spew logging"
SPEW.Register()
+ CHANGE.B = false
+ CHANGE.Name = "CHANGE"
+ CHANGE.Subsystem = "cpdns"
+ CHANGE.Desc = "show droplet state changes"
+ CHANGE.Register()
+
if debugger.ArgDebug() {
log.Log(true, "INIT() gui debug == true")
} else {
@@ -50,5 +71,5 @@ func init() {
me.artificialS = "blah"
log.Log(true, "init() me.artificialSleep =", me.artificialSleep)
log.Log(true, "init() me.artificialS =", me.artificialS)
- sleep(me.artificialSleep)
+ log.Sleep(me.artificialSleep)
}
diff --git a/bash.go b/bash.go
index 5c49a39..7143c1f 100644
--- a/bash.go
+++ b/bash.go
@@ -2,7 +2,6 @@ package main
import (
"io"
- "log"
"os"
"os/exec"
"os/signal"
@@ -10,6 +9,8 @@ import (
"github.com/creack/pty"
"golang.org/x/term"
+
+ "go.wit.com/log"
)
func test() error {
@@ -54,7 +55,7 @@ func test() error {
func mainBash() {
if err := test(); err != nil {
- debug(LogError, "exit in mainBash()")
- exit(err)
+ log.Error(err, "exit in mainBash()")
+ log.Exit(err)
}
}
diff --git a/dns.go b/dns.go
index fc9648c..a2e4763 100644
--- a/dns.go
+++ b/dns.go
@@ -5,10 +5,10 @@
package main
import (
- "log"
"net"
"strings"
+ "go.wit.com/log"
"go.wit.com/shell"
)
@@ -27,7 +27,7 @@ func (h *Host) verifyETC() bool {
func (h *Host) updateIPs(host string) {
ips, err := net.LookupIP(host)
if err != nil {
- debug(LogError, "updateIPs failed", err)
+ log.Error(err, "updateIPs failed")
}
for _, ip := range ips {
log.Println(host, ip)
@@ -93,7 +93,7 @@ func lookupNS(domain string) {
for _, server := range servers {
server = strings.TrimRight(server, ".")
if (me.nsmap[server] != domain) {
- debug(LogChange, "lookupNS() domain", domain, "has NS", server)
+ log.Log(CHANGE, "lookupNS() domain", domain, "has NS", server)
me.nsmap[server] = domain
domains += server + "\n"
}
@@ -102,7 +102,7 @@ func lookupNS(domain string) {
var tmp string
// checks to see if the NS records change
for s, d := range me.nsmap {
- debug(LogChange, "lookupNS() domain =", d, "server =", s)
+ log.Log(CHANGE, "lookupNS() domain =", d, "server =", s)
if (domain == d) {
tmp += s + "\n"
// figure out the provider (google, cloudflare, etc)
@@ -113,7 +113,7 @@ func lookupNS(domain string) {
if (tmp != me.NSrr.S) {
me.changed = true
- debug(LogChange, "lookupNS() setting me.NSrr =", tmp)
+ log.Log(CHANGE, "lookupNS() setting me.NSrr =", tmp)
me.NSrr.SetText(tmp)
}
}
@@ -127,7 +127,7 @@ func setProvider(hostname string) {
}
if (me.DnsAPI.S != provider) {
me.changed = true
- debug(LogChange, "setProvider() changed to =", provider)
+ log.Log(CHANGE, "setProvider() changed to =", provider)
me.DnsAPI.SetText(provider)
}
}
diff --git a/fsnotify.go b/fsnotify.go
index 23809e6..cf38b50 100644
--- a/fsnotify.go
+++ b/fsnotify.go
@@ -3,7 +3,7 @@ package main
// Watches for changes to a directory. Works cross-platform
import (
- "log"
+ "go.wit.com/log"
"github.com/fsnotify/fsnotify"
)
@@ -14,7 +14,7 @@ func watchSysClassNet() {
// Create new watcher.
watcher, err := fsnotify.NewWatcher()
if err != nil {
- debug(LogError, "watchSysClassNet() failed:", err)
+ log.Error(err, "watchSysClassNet() failed")
return
}
defer watcher.Close()
@@ -43,7 +43,7 @@ func watchSysClassNet() {
// Add a path.
err = watcher.Add("/tmp")
if err != nil {
- debug(LogError, "watchSysClassNet() watcher.Add() failed:", err)
+ log.Error(err, "watchSysClassNet() watcher.Add() failed")
return
}
diff --git a/gui.go b/gui.go
index aba83ad..b2dc74b 100644
--- a/gui.go
+++ b/gui.go
@@ -22,8 +22,8 @@ func setupControlPanelWindow() {
me.window = myGui.NewWindow("DNS and IPv6 Control Panel")
// me.window.Dump() // will dump out some info
- debug("artificial sleep of:", me.artificialSleep)
- sleep(me.artificialSleep)
+ log.Info("artificial sleep of:", me.artificialSleep)
+ log.Sleep(me.artificialSleep)
// setup the main tab
dnsTab("DNS")
@@ -109,10 +109,10 @@ func debugTab(title string) {
g2.NewButton("checkDNS:", func () {
ipv6s, ipv4s := checkDNS()
for s, _ := range ipv6s {
- debug(LogNow, "check if", s, "is in DNS")
+ log.Log(NOW, "check if", s, "is in DNS")
}
for s, _ := range ipv4s {
- debug(LogNow, "check if", s, "is in DNS")
+ log.Log(NOW, "check if", s, "is in DNS")
}
})
@@ -153,19 +153,14 @@ func debugTab(title string) {
g2 = tab.NewGroup("debugging options")
// DEBUG flags
- me.dbOn = g2.NewCheckbox("turn on debugging (will override all flags below)")
- me.dbOn.Custom = func() {
- DEBUGON = me.dbOn.B
- }
-
me.dbNet = g2.NewCheckbox("turn on network debugging)")
me.dbNet.Custom = func() {
- LogNet = me.dbNet.B
+ log.Warn("TODO: re-implement")
}
me.dbProc = g2.NewCheckbox("turn on /proc debugging)")
me.dbProc.Custom = func() {
- LogProc = me.dbProc.B
+ log.Warn("TODO: re-implement")
}
// makes a slider widget
@@ -185,7 +180,7 @@ func deleteAAA() string {
var aaaa []string
aaaa = dhcpAAAA() // your AAAA IP addresses right now
for _, s := range aaaa {
- debug(LogNow, "DNS AAAA =", s)
+ log.Log(NOW, "DNS AAAA =", s)
if ( me.ipmap[s] == nil) {
return s
}
@@ -198,7 +193,7 @@ func missingAAAA() string {
var aaaa []string
aaaa = dhcpAAAA() // your AAAA IP addresses right now
for _, s := range aaaa {
- debug(LogNow, "missing AAAA =", s)
+ log.Log(NOW, "missing AAAA =", s)
return s
}
return ""
@@ -213,10 +208,10 @@ func displayDNS() string {
var all string
var broken string = "unknown"
for _, s := range aaaa {
- debug(LogNow, "host", h, "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
+ log.Log(NOW, "host", h, "DNS AAAA =", s, "ipmap[s] =", me.ipmap[s])
all += s + "\n"
if ( me.ipmap[s] == nil) {
- debug(LogError, "THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
+ log.Warn("THIS IS THE WRONG AAAA DNS ENTRY: host", h, "DNS AAAA =", s)
broken = "wrong AAAA entry"
} else {
if (broken == "unknown") {
@@ -226,7 +221,7 @@ func displayDNS() string {
}
all = sortLines(all)
if (me.workingIPv6.S != all) {
- debug(LogError, "workingIPv6.SetText() to:", all)
+ log.Warn("workingIPv6.SetText() to:", all)
me.workingIPv6.SetText(all)
}
@@ -234,11 +229,11 @@ func displayDNS() string {
a = realA()
all = sortLines(strings.Join(a, "\n"))
if (all == "") {
- debug(LogInfo, "THERE IS NOT a real A DNS ENTRY")
+ log.Info("THERE IS NOT a real A DNS ENTRY")
all = "CNAME ipv6.wit.com"
}
if (me.DnsA.S != all) {
- debug(LogError, "DnsA.SetText() to:", all)
+ log.Warn("DnsA.SetText() to:", all)
me.DnsA.SetText(all)
}
return broken
@@ -270,9 +265,9 @@ func dnsTab(title string) {
me.fix = me.mainStatus.NewButton("Fix", func () {
if (goodHostname(me.hostname)) {
- debug(LogInfo, "hostname is good:", me.hostname)
+ log.Info("hostname is good:", me.hostname)
} else {
- debug(LogError, "FIX: you need to fix your hostname here", me.hostname)
+ log.Warn("FIX: you need to fix your hostname here", me.hostname)
return
}
// check to see if the cloudflare window exists
@@ -396,11 +391,11 @@ func updateDNS() {
// log.Println("digAAAA()")
aaaa = digAAAA(h)
- debug(LogNow, "digAAAA() =", aaaa)
+ log.Log(NOW, "digAAAA() =", aaaa)
// log.Println(SPEW, me)
if (aaaa == nil) {
- debug(LogError, "There are no DNS AAAA records for hostname: ", h)
+ log.Warn("There are no DNS AAAA records for hostname: ", h)
me.DnsAAAA.SetText("(none)")
if (cloudflare.CFdialog.TypeNode != nil) {
cloudflare.CFdialog.TypeNode.SetText("AAAA new")
@@ -467,14 +462,12 @@ func suggestProcDebugging() {
}
me.fixProc = me.mainStatus.NewButton("Try debugging Slow DNS lookups", func () {
- debug("You're DNS lookups are very slow")
+ log.Warn("You're DNS lookups are very slow")
me.dbOn.Set(true)
me.dbProc.Set(true)
- DEBUGON = true
- LogProc = true
processName := getProcessNameByPort(53)
- log.Println("Process with port 53:", processName)
+ log.Info("Process with port 53:", processName)
})
// me.fixProc.Disable()
}
diff --git a/hostname.go b/hostname.go
index 9a01b35..c3a2e1f 100644
--- a/hostname.go
+++ b/hostname.go
@@ -19,7 +19,7 @@ func getHostname() {
var s string = "gui.Label == nil"
s, err = fqdn.FqdnHostname()
if (err != nil) {
- debug(LogError, "FQDN hostname error =", err)
+ log.Error(err, "FQDN hostname error")
return
}
if (me.fqdn != nil) {
@@ -29,18 +29,18 @@ func getHostname() {
me.changed = true
}
}
- debug(LogNet, "FQDN =", s)
+ log.Log(NET, "FQDN =", s)
dn := run("domainname")
if (me.domainname.S != dn) {
- debug(LogChange, "domainname has changed from", me.domainname.S, "to", dn)
+ log.Log(CHANGE, "domainname has changed from", me.domainname.S, "to", dn)
me.domainname.SetText(dn)
me.changed = true
}
hshort := run("hostname -s")
if (me.hostshort.S != hshort) {
- debug(LogChange, "hostname -s has changed from", me.hostshort.S, "to", hshort)
+ log.Log(CHANGE, "hostname -s has changed from", me.hostshort.S, "to", hshort)
me.hostshort.SetText(hshort)
me.changed = true
}
@@ -48,21 +48,21 @@ func getHostname() {
var test string
test = hshort + "." + dn
if (me.hostname != test) {
- debug(LogInfo, "me.hostname", me.hostname, "does not equal", test)
+ log.Info("me.hostname", me.hostname, "does not equal", test)
if (me.hostnameStatusOLD.S != "BROKEN") {
- debug(LogChange, "me.hostname", me.hostname, "does not equal", test)
+ log.Log(CHANGE, "me.hostname", me.hostname, "does not equal", test)
me.changed = true
me.hostnameStatusOLD.SetText("BROKEN")
}
} else {
if (me.hostnameStatusOLD.S != "VALID") {
- debug(LogChange, "me.hostname", me.hostname, "is valid")
+ log.Log(CHANGE, "me.hostname", me.hostname, "is valid")
me.hostnameStatusOLD.SetText("VALID")
me.changed = true
}
// enable the cloudflare button if the provider is cloudflare
if (me.cloudflareB == nil) {
- debug(LogChange, "me.cloudflare == nil; me.DnsAPI.S =", me.DnsAPI.S)
+ log.Log(CHANGE, "me.cloudflare == nil; me.DnsAPI.S =", me.DnsAPI.S)
if (me.DnsAPI.S == "cloudflare") {
me.cloudflareB = me.mainStatus.NewButton("cloudflare wit.com", func () {
cloudflare.CreateRR(myGui, "wit.com", "3777302ac4a78cd7fa4f6d3f72086d06")
@@ -78,15 +78,15 @@ func getHostname() {
// and domainname and hostname
func goodHostname(h string) bool {
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
- debug(true, "hostname =", hostname)
+ log.Log(NOW, "hostname =", hostname)
hs := run("hostname -s")
dn := run("domainname")
- debug(true, "hostname short =", hs, "domainname =", dn)
+ log.Log(NOW, "hostname short =", hs, "domainname =", dn)
tmp := hs + "." + dn
if (hostname == tmp) {
- debug(true, "hostname seems to be good", hostname)
+ log.Log(NOW, "hostname seems to be good", hostname)
return true
}
@@ -98,18 +98,18 @@ func digAAAA(s string) []string {
var aaaa []string
// lookup the IP address from DNS
rrset := dnssecsocket.Dnstrace(s, "AAAA")
- // debug(true, args.VerboseDNS, SPEW, rrset)
+ // log.Spew(args.VerboseDNS, SPEW, rrset)
for i, rr := range rrset {
ipaddr := dns.Field(rr, 1)
// how the hell do you detect a RRSIG AAAA record here?
if (ipaddr == "28") {
continue
}
- debug(LogNow, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
+ log.Log(NOW, "r.Answer =", i, "rr =", rr, "ipaddr =", ipaddr)
aaaa = append(aaaa, ipaddr)
me.ipv6s[ipaddr] = rr
}
- debug(true, args.VerboseDNS, "aaaa =", aaaa)
+ log.Info(args.VerboseDNS, "aaaa =", aaaa)
log.Println("digAAAA() returned =", aaaa)
log.Println("digAAAA() me.ipv6s =", me.ipv6s)
os.Exit(0)
diff --git a/hostnameStatus.go b/hostnameStatus.go
index f25598b..f396ba5 100644
--- a/hostnameStatus.go
+++ b/hostnameStatus.go
@@ -247,7 +247,7 @@ func (hs *hostnameStatus) missingAAAA() bool {
var aaaa []string
aaaa = dhcpAAAA()
for _, s := range aaaa {
- debug(LogNet, "my actual AAAA = ",s)
+ log.Log(NET, "my actual AAAA = ",s)
hs.dnsValue.SetText(s)
hs.dnsAction.SetText("CREATE")
return true
diff --git a/log.go b/log.go
deleted file mode 100644
index 9039905..0000000
--- a/log.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package main
-
-import (
- "log"
- "reflect"
- witlog "go.wit.com/log"
-)
-
-var LogPrefix = "ipv6cp" // ipv6 control panel debugging line
-
-// various debugging flags
-var DEBUGON bool = true
-var LogNow bool = true // useful for active development
-var LogError bool = true // probably always leave this one
-var LogChange bool = true // turn on /proc debugging output
-
-var LogInfo bool = false // general info
-var LogNet bool = false // general network debugging
-var LogProc bool = false // turn on /proc debugging output
-var LogExec bool = false // turn on os.Exec() debugging
-
-// var SPEW witlog.Spewt
-
-// var log interface{}
-
-/*
-func log(a ...any) {
- witlog.Where = "wit/gui"
- witlog.Log(a...)
-}
-*/
-
-func sleep(a ...any) {
- witlog.Sleep(a...)
-}
-
-func exit(a ...any) {
- debug(LogError, "got to log() exit")
- witlog.Exit(a...)
-}
-
-func debug(a ...any) {
- if (! DEBUGON) {
- return
- }
-
- if (a == nil) {
- return
- }
- var tbool bool
- if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) {
- if (a[0] == false) {
- return
- }
- a[0] = LogPrefix // ipv6 control panel debugging line
- }
-
- log.Println(a...)
-}
diff --git a/main.go b/main.go
index 6dc3b53..0957d70 100644
--- a/main.go
+++ b/main.go
@@ -43,16 +43,16 @@ func main() {
myGui = gui.New().Default()
- sleep(me.artificialSleep)
+ log.Sleep(me.artificialSleep)
setupControlPanelWindow()
if debugger.ArgDebug() {
- sleep(2)
+ log.Sleep(2)
debugger.DebugWindow(myGui)
}
// forever monitor for network and dns changes
- sleep(me.artificialSleep)
+ log.Sleep(me.artificialSleep)
checkNetworkChanges()
}
@@ -99,7 +99,7 @@ func checkNetworkChanges() {
me.LocalSpeedActual.SetText(s)
} else {
// TODO: make windows and macos diagnostics
- debug(LogError, "Windows and MacOS don't work yet")
+ log.Warn("Windows and MacOS don't work yet")
}
lastLocal = time.Now()
}
@@ -120,7 +120,7 @@ func checkNetworkChanges() {
// run this on each timeout
func DNSloop() {
duration := timeFunction(dnsTTL)
- debug(LogInfo, "dnsTTL() execution Time: ", duration)
+ log.Info("dnsTTL() execution Time: ", duration)
var s, newSpeed string
if (duration > 5000 * time.Millisecond ) {
newSpeed = "VERY BAD"
@@ -143,8 +143,8 @@ func DNSloop() {
}
}
if (newSpeed != me.DnsSpeedLast) {
- debug(LogChange, "dns lookup speed changed =", newSpeed)
- debug(LogChange, "dnsTTL() execution Time: ", duration)
+ log.Log(CHANGE, "dns lookup speed changed =", newSpeed)
+ log.Log(CHANGE, "dnsTTL() execution Time: ", duration)
me.DnsSpeed.SetText(newSpeed)
me.DnsSpeedLast = newSpeed
}
@@ -160,30 +160,30 @@ func dnsTTL() {
func linuxLoop() {
me.changed = false
- debug(LogNet, "FQDN =", me.fqdn.GetText())
+ log.Log(NET, "FQDN =", me.fqdn.GetText())
duration := timeFunction(getHostname)
- debug(LogInfo, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
+ log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
duration = timeFunction(scanInterfaces)
- debug(LogNet, "scanInterfaces() execution Time: ", duration)
+ log.Log(NET, "scanInterfaces() execution Time: ", duration)
for i, t := range me.ifmap {
- debug(LogNet, strconv.Itoa(i) + " iface = " + t.iface.Name)
+ log.Log(NET, strconv.Itoa(i) + " iface = " + t.iface.Name)
}
var aaaa []string
aaaa = dhcpAAAA()
var all string
for _, s := range aaaa {
- debug(LogNet, "my actual AAAA = ",s)
+ log.Log(NET, "my actual AAAA = ",s)
all += s + "\n"
}
// me.IPv6.SetText(all)
if (me.changed) {
stamp := time.Now().Format("2006/01/02 15:04:05")
- debug(LogChange, "Network things changed on", stamp)
+ log.Log(CHANGE, "Network things changed on", stamp)
duration := timeFunction(updateDNS)
- debug(LogChange, "updateDNS() execution Time: ", duration)
+ log.Log(CHANGE, "updateDNS() execution Time: ", duration)
}
/*
diff --git a/net.go b/net.go
index d8aaaa6..6f27c27 100644
--- a/net.go
+++ b/net.go
@@ -270,7 +270,7 @@ func deleteChanges() bool {
var changed bool = false
for i, t := range me.ifmap {
if (t.gone) {
- log.Log(LogChange, "DELETE int =", i, "name =", t.name, t.iface)
+ log.Log(CHANGE, "DELETE int =", i, "name =", t.name, t.iface)
delete(me.ifmap, i)
changed = true
}
@@ -278,10 +278,10 @@ func deleteChanges() bool {
}
for s, t := range me.ipmap {
if (t.gone) {
- log.Log(LogChange, "DELETE name =", s, "IPv4 =", t.ipv4)
- log.Log(LogChange, "DELETE name =", s, "IPv6 =", t.ipv6)
- log.Log(LogChange, "DELETE name =", s, "iface =", t.iface)
- log.Log(LogChange, "DELETE name =", s, "ip =", t.ip)
+ log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4)
+ log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6)
+ log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface)
+ log.Log(CHANGE, "DELETE name =", s, "ip =", t.ip)
delete(me.ipmap, s)
changed = true
}
diff --git a/nsupdate.go b/nsupdate.go
index 6aef147..d86178f 100644
--- a/nsupdate.go
+++ b/nsupdate.go
@@ -7,6 +7,8 @@ package main
import (
"os"
+
+ "go.wit.com/log"
)
// ./go-nsupdate \
@@ -16,17 +18,17 @@ import (
func nsupdate() {
var tsigSecret string
- debug(true, "nsupdate() START")
+ log.Log(NET, "nsupdate() START")
cmd := "go-nsupdate --tsig-algorithm=hmac-sha512"
tsigSecret = os.Getenv("TIG_SECRET")
cmd += " --tig-secret=\"" + tsigSecret + "\""
cmd += " -i wlo1 " + me.hostname
- debug(true, "nsupdate() RUN:", cmd)
+ log.Log(NET, "nsupdate() RUN:", cmd)
for s, t := range me.ipmap {
if (t.IsReal()) {
if (t.ipv6) {
- debug(true, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
+ log.Log(NET, "nsupdate() found real AAAA =", s, "on iface", t.iface.Name)
}
}
}
diff --git a/proc.go b/proc.go
index bf78c16..adc8576 100644
--- a/proc.go
+++ b/proc.go
@@ -6,6 +6,8 @@ import (
"path/filepath"
"strconv"
"strings"
+
+ "go.wit.com/log"
)
func getProcessNameByPort(port int) string {
@@ -18,24 +20,24 @@ func getProcessNameByPort(port int) string {
if err != nil {
return ""
}
- // debug(LogProc, "searchProcNet() data:", string(data))
+ // log.Log(PROC, "searchProcNet() data:", string(data))
lines := strings.Split(string(data), "\n")
for _, line := range lines {
fields := strings.Fields(line)
- debug(LogProc, "searchProcNet() portHex:", portHex)
+ log.Log(PROC, "searchProcNet() portHex:", portHex)
if (len(fields) > 9) {
- debug(LogProc, "searchProcNet() fields[9]", fields[9])
+ log.Log(PROC, "searchProcNet() fields[9]", fields[9])
}
- debug(LogProc, "searchProcNet() lines:", line)
+ log.Log(PROC, "searchProcNet() lines:", line)
if len(fields) > 1 {
parts := strings.Split(fields[1], ":")
if len(parts) > 1 {
// Convert the hexadecimal string to an integer
value, _ := strconv.ParseInt(parts[1], 16, 64)
- debug(LogProc, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1])
+ log.Log(PROC, "searchProcNet() value, port =", value, port, "parts[1] =", parts[1])
if (port == int(value)) {
- debug(LogProc, "searchProcNet() THIS IS THE LINE:", fields)
+ log.Log(PROC, "searchProcNet() THIS IS THE LINE:", fields)
return fields[9]
}
}
@@ -50,7 +52,7 @@ func getProcessNameByPort(port int) string {
if inode == "" {
inode = searchProcNet("/proc/net/udp")
}
- debug(LogProc, "searchProcNet() inode =", inode)
+ log.Log(PROC, "searchProcNet() inode =", inode)
// Search for process with the inode
procs, _ := ioutil.ReadDir("/proc")
@@ -70,23 +72,23 @@ func getProcessNameByPort(port int) string {
var s string
s = "socket:["+inode+"]"
if strings.Contains(fdLink, "socket:[") {
- debug(LogProc, "searchProcNet() fdLink has socket:", fdLink)
- debug(LogProc, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
+ log.Log(PROC, "searchProcNet() fdLink has socket:", fdLink)
+ log.Log(PROC, "searchProcNet() proc.Name() =", proc.Name(), "s =", s)
}
if strings.Contains(fdLink, "socket:[35452]") {
- debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
+ log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
return proc.Name()
}
if strings.Contains(fdLink, "socket:[35450]") {
- debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
+ log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
return proc.Name()
}
if strings.Contains(fdLink, "socket:[35440]") {
- debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
+ log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
return proc.Name()
}
if strings.Contains(fdLink, "socket:[21303]") {
- debug(LogProc, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
+ log.Log(PROC, "searchProcNet() found proc.Name() =", proc.Name(), fdLink)
// return proc.Name()
}
if strings.Contains(fdLink, "socket:["+inode+"]") {
diff --git a/rtnetlink.go b/rtnetlink.go
index d4449c0..29f1153 100644
--- a/rtnetlink.go
+++ b/rtnetlink.go
@@ -1,8 +1,8 @@
package main
import (
- "log"
"github.com/jsimonetti/rtnetlink"
+ "go.wit.com/log"
)
// List all interfaces
@@ -10,7 +10,7 @@ func Example_listLink() {
// Dial a connection to the rtnetlink socket
conn, err := rtnetlink.Dial(nil)
if err != nil {
- debug(LogError, "Example_listLink() failed", err)
+ log.Error(err, "Example_listLink() failed")
return
}
defer conn.Close()
diff --git a/unix.go b/unix.go
index 722ec82..b09481a 100644
--- a/unix.go
+++ b/unix.go
@@ -5,7 +5,6 @@
package main
import (
- "log"
"os"
"os/exec"
"net"
@@ -13,6 +12,7 @@ import (
"fmt"
"strings"
+ "go.wit.com/log"
"go.wit.com/shell"
)
@@ -28,8 +28,8 @@ func Escalate() {
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
- debug(LogError, "exit in Escalate()")
- exit(err)
+ log.Error(err, "exit in Escalate()")
+ log.Exit(err)
}
}
}
@@ -50,7 +50,7 @@ func DumpPublicDNSZone(zone string) {
func dumpIPs(host string) {
ips, err := net.LookupIP(host)
if err != nil {
- debug(LogError, "dumpIPs() failed:", err)
+ log.Error(err, "dumpIPs() failed")
}
for _, ip := range ips {
log.Println(host, ip)
@@ -91,7 +91,7 @@ func run(s string) string {
tmp := shell.Chomp(out.String())
// Output the results
- debug(LogExec, "Command Output:", tmp)
+ log.Info("Command Output:", tmp)
return tmp
}