Adding some debug options

This commit is contained in:
Matt Burchett 2019-01-14 12:36:15 -06:00
parent 43ed2ea438
commit d98ac3058e
3 changed files with 21 additions and 2 deletions

View File

@ -33,6 +33,6 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
data := resolver.PerformZoneTransfer(cfg) data := resolver.PerformZoneTransfer(cfg, debug)
shell.CreateShellAliases(data, user, cfg) shell.CreateShellAliases(data, user, cfg)
} }

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"rfi-sower/pkg/utils"
"strings" "strings"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
@ -29,7 +30,10 @@ func lookupName(fqdn, serverAddr string) (string, error) {
} }
// PerformZoneTransfer performs zone transfers and gathers a list from config.Domains // PerformZoneTransfer performs zone transfers and gathers a list from config.Domains
func PerformZoneTransfer(config config.Config) []string { func PerformZoneTransfer(config config.Config, debug bool) []string {
if debug {
defer utils.LogElapsedTime("Perform Zone Transfer")
}
data := make([]string, 0) data := make([]string, 0)
// Do the transfer // Do the transfer

15
pkg/utils/logging.go Normal file
View File

@ -0,0 +1,15 @@
package utils
import (
"log"
"time"
)
//LogElapsedTime provides a function that can be used to log the time elapsed between when this function is invoked, to the time the returned function is invoked.
//Adding "defer LogElapsedTime("my log")" at the beginning of any function will log the time it takes to execute that function.
func LogElapsedTime(what string) func() {
start := time.Now()
return func() {
log.Printf("%s, Total Time Taken: %v\n", what, time.Since(start))
}
}