Commit 947209a0 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: PACKER_LOG to toggle logging from an env var [GH-3]

parent 7dfeda35
...@@ -5,12 +5,21 @@ import ( ...@@ -5,12 +5,21 @@ import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer/plugin" "github.com/mitchellh/packer/packer/plugin"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
) )
func main() { func main() {
if os.Getenv("PACKER_LOG") == "" {
// If we don't have logging explicitly enabled, then disable it
log.SetOutput(ioutil.Discard)
} else {
// Logging is enabled, make sure it goes to stderr
log.SetOutput(os.Stderr)
}
defer plugin.CleanupClients() defer plugin.CleanupClients()
commands := map[string]string { commands := map[string]string {
......
...@@ -4,6 +4,7 @@ package packer ...@@ -4,6 +4,7 @@ package packer
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"sort" "sort"
"strings" "strings"
...@@ -87,6 +88,8 @@ func (e *coreEnvironment) Builder(name string) (b Builder, err error) { ...@@ -87,6 +88,8 @@ func (e *coreEnvironment) Builder(name string) (b Builder, err error) {
// Executes a command as if it was typed on the command-line interface. // Executes a command as if it was typed on the command-line interface.
// The return value is the exit code of the command. // The return value is the exit code of the command.
func (e *coreEnvironment) Cli(args []string) (result int, err error) { func (e *coreEnvironment) Cli(args []string) (result int, err error) {
log.Printf("Environment.Cli: %#v\n", args)
if len(args) == 0 || args[0] == "--help" || args[0] == "-h" { if len(args) == 0 || args[0] == "--help" || args[0] == "-h" {
e.printHelp() e.printHelp()
return 1, nil return 1, nil
...@@ -115,6 +118,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { ...@@ -115,6 +118,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) {
// If we still don't have a command, show the help. // If we still don't have a command, show the help.
if command == nil { if command == nil {
log.Printf("Environment.CLI: command not found: %s\n", args[0])
e.printHelp() e.printHelp()
return 1, nil return 1, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment