Merge pull request #4200 from hashicorp/phinze/logging-acctests
core: use same logging setup for acctests
This commit is contained in:
commit
238dfff24c
|
@ -1,7 +1,8 @@
|
||||||
package main
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -18,9 +19,9 @@ const (
|
||||||
|
|
||||||
var validLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
|
var validLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
|
||||||
|
|
||||||
// logOutput determines where we should send logs (if anywhere) and the log level.
|
// LogOutput determines where we should send logs (if anywhere) and the log level.
|
||||||
func logOutput() (logOutput io.Writer, err error) {
|
func LogOutput() (logOutput io.Writer, err error) {
|
||||||
logOutput = nil
|
logOutput = ioutil.Discard
|
||||||
envLevel := os.Getenv(EnvLog)
|
envLevel := os.Getenv(EnvLog)
|
||||||
if envLevel == "" {
|
if envLevel == "" {
|
||||||
return
|
return
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/go-getter"
|
"github.com/hashicorp/go-getter"
|
||||||
"github.com/hashicorp/terraform/config/module"
|
"github.com/hashicorp/terraform/config/module"
|
||||||
|
"github.com/hashicorp/terraform/helper/logging"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -103,6 +104,12 @@ func Test(t TestT, c TestCase) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logWriter, err := logging.LogOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(fmt.Errorf("error setting up logging: %s", err))
|
||||||
|
}
|
||||||
|
log.SetOutput(logWriter)
|
||||||
|
|
||||||
// We require verbose mode so that the user knows what is going on.
|
// We require verbose mode so that the user knows what is going on.
|
||||||
if !testTesting && !testing.Verbose() {
|
if !testTesting && !testing.Verbose() {
|
||||||
t.Fatal("Acceptance tests must be run with the -v flag on tests")
|
t.Fatal("Acceptance tests must be run with the -v flag on tests")
|
||||||
|
|
10
main.go
10
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/logging"
|
||||||
"github.com/hashicorp/terraform/plugin"
|
"github.com/hashicorp/terraform/plugin"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/mitchellh/panicwrap"
|
"github.com/mitchellh/panicwrap"
|
||||||
|
@ -23,14 +24,11 @@ func realMain() int {
|
||||||
|
|
||||||
if !panicwrap.Wrapped(&wrapConfig) {
|
if !panicwrap.Wrapped(&wrapConfig) {
|
||||||
// Determine where logs should go in general (requested by the user)
|
// Determine where logs should go in general (requested by the user)
|
||||||
logWriter, err := logOutput()
|
logWriter, err := logging.LogOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
|
fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
if logWriter == nil {
|
|
||||||
logWriter = ioutil.Discard
|
|
||||||
}
|
|
||||||
|
|
||||||
// We always send logs to a temporary file that we use in case
|
// We always send logs to a temporary file that we use in case
|
||||||
// there is a panic. Otherwise, we delete it.
|
// there is a panic. Otherwise, we delete it.
|
||||||
|
@ -42,10 +40,6 @@ func realMain() int {
|
||||||
defer os.Remove(logTempFile.Name())
|
defer os.Remove(logTempFile.Name())
|
||||||
defer logTempFile.Close()
|
defer logTempFile.Close()
|
||||||
|
|
||||||
// Tell the logger to log to this file
|
|
||||||
os.Setenv(EnvLog, "")
|
|
||||||
os.Setenv(EnvLogFile, "")
|
|
||||||
|
|
||||||
// Setup the prefixed readers that send data properly to
|
// Setup the prefixed readers that send data properly to
|
||||||
// stdout/stderr.
|
// stdout/stderr.
|
||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
|
|
Loading…
Reference in New Issue