add logging behind "PACKER_OCI_CLASSIC_LOGGING" env var

This commit is contained in:
Matthew Hooker 2018-01-25 16:12:03 -08:00
parent 0fad49e897
commit 77277ebc98
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package classic
import (
"fmt"
"log"
"os"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-oracle-terraform/compute"
@ -35,6 +36,7 @@ func (b *Builder) Prepare(rawConfig ...interface{}) ([]string, error) {
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
loggingEnabled := os.Getenv("PACKER_OCI_CLASSIC_LOGGING")) != ""
httpClient := cleanhttp.DefaultClient()
config := &opc.Config{
Username: opc.String(b.config.Username),
@ -42,6 +44,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
IdentityDomain: opc.String(b.config.IdentityDomain),
APIEndpoint: b.config.apiEndpointURL,
LogLevel: opc.LogDebug,
Logger: &Logger{loggingEnabled},
// Logger: # Leave blank to use the default logger, or provide your own
HTTPClient: httpClient,
}

View File

@ -0,0 +1,14 @@
package classic
import "log"
type Logger struct {
Enabled bool
}
func (l *Logger) Log(input ...interface{}) {
if !l.Enabled {
return
}
log.Println(input...)
}