Skip to content

Commit

Permalink
refactor: conditional debug logging for service registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Sep 12, 2019
1 parent c40decc commit bde5314
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azurerm
import (
"fmt"
"log"
"os"

"github.com/hashicorp/go-azure-helpers/authentication"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -434,8 +435,16 @@ func Provider() terraform.ResourceProvider {
"azurerm_web_application_firewall_policy": resourceArmWebApplicationFirewallPolicy(),
}

// avoids this showing up in test output
var debugLog = func(f string, v ...interface{}) {
if os.Getenv("TF_LOG") == "" {
return
}

log.Printf(f, v...)
}
for _, service := range supportedServices {
log.Printf("[DEBUG] Registering Data Sources for %q..", service.Name())
debugLog("[DEBUG] Registering Data Sources for %q..", service.Name())
for k, v := range service.SupportedDataSources() {
if existing := dataSources[k]; existing != nil {
panic(fmt.Sprintf("An existing Data Source exists for %q", k))
Expand All @@ -444,7 +453,7 @@ func Provider() terraform.ResourceProvider {
dataSources[k] = v
}

log.Printf("[DEBUG] Registering Resources for %q..", service.Name())
debugLog("[DEBUG] Registering Resources for %q..", service.Name())
for k, v := range service.SupportedResources() {
if existing := resources[k]; existing != nil {
panic(fmt.Sprintf("An existing Resource exists for %q", k))
Expand Down

0 comments on commit bde5314

Please sign in to comment.