diff --git a/cmd/main.go b/cmd/main.go index 89716a4..191c43e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,6 +33,6 @@ func main() { log.Fatal(err) } - data := resolver.PerformZoneTransfer(cfg) + data := resolver.PerformZoneTransfer(cfg, debug) shell.CreateShellAliases(data, user, cfg) } diff --git a/pkg/resolver/resolver.go b/pkg/resolver/resolver.go index 460a6bc..a78d74e 100644 --- a/pkg/resolver/resolver.go +++ b/pkg/resolver/resolver.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "log" + "rfi-sower/pkg/utils" "strings" "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 -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) // Do the transfer diff --git a/pkg/utils/logging.go b/pkg/utils/logging.go new file mode 100644 index 0000000..be17f71 --- /dev/null +++ b/pkg/utils/logging.go @@ -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)) + } +}