Skip to content

Commit 2149d59

Browse files
authored
Merge pull request #200 from commitdev/improved-debug-logging
Improved debug logging
2 parents e8d62a9 + 7b70d83 commit 2149d59

File tree

11 files changed

+70
-8
lines changed

11 files changed

+70
-8
lines changed

cmd/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/commitdev/zero/internal/config/projectconfig"
77
initPrompts "github.com/commitdev/zero/internal/init"
88
"github.com/commitdev/zero/pkg/util/exit"
9+
"github.com/commitdev/zero/pkg/util/flog"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -17,6 +18,7 @@ var initCmd = &cobra.Command{
1718
Use: "init",
1819
Short: "Create new project with provided name and initialize configuration based on user input.",
1920
Run: func(cmd *cobra.Command, args []string) {
21+
flog.Debugf("Root directory is %s", projectconfig.RootDir)
2022
projectContext := initPrompts.Init(projectconfig.RootDir)
2123
projectConfigErr := projectconfig.CreateProjectConfigFile(projectconfig.RootDir, projectContext.Name, projectContext)
2224

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
github.com/matryer/is v1.3.0 // indirect
2121
github.com/mattn/go-colorable v0.1.2 // indirect
2222
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
23+
github.com/sirupsen/logrus v1.2.0
2324
github.com/spf13/cobra v0.0.6
2425
github.com/stretchr/testify v1.5.1
2526
github.com/termie/go-shutil v0.0.0-20140729215957-bcacb06fecae

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
331331
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
332332
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
333333
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
334+
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
334335
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
335336
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
336337
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
@@ -392,6 +393,7 @@ golang.org/x/crypto v0.0.0-20190222235706-ffb98f73852f/go.mod h1:6SG95UA2DQfeDnf
392393
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
393394
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
394395
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
396+
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
395397
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
396398
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
397399
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=

internal/apply/apply.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEn
7878
if module.IsLocal(mod.Files.Source) && !filepath.IsAbs(modulePath) {
7979
modulePath = filepath.Join(dir, modulePath)
8080
}
81+
flog.Debugf("Loaded module: %s from %s", name, modulePath)
8182

8283
// TODO: in the case user lost the `/tmp` (module source dir), this will fail
8384
// and we should redownload the module for the user
@@ -91,6 +92,7 @@ func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEn
9192
credentialEnvs := credentials.SelectedVendorsCredentialsAsEnv(modConfig.RequiredCredentials)
9293
envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList)
9394
envList = util.AppendProjectEnvToCmdEnv(credentialEnvs, envList)
95+
flog.Debugf("Env injected: %#v", envList)
9496
util.ExecuteCommand(exec.Command("make"), modulePath, envList)
9597
return nil
9698
})
@@ -158,8 +160,10 @@ func summarizeAll(dir string, projectConfig projectconfig.ZeroProjectConfig, app
158160
if module.IsLocal(mod.Files.Source) && !filepath.IsAbs(modulePath) {
159161
modulePath = filepath.Join(dir, modulePath)
160162
}
163+
flog.Debugf("Loaded module: %s from %s", name, modulePath)
161164

162165
envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList)
166+
flog.Debugf("Env injected: %#v", envList)
163167
util.ExecuteCommand(exec.Command("make", "summary"), modulePath, envList)
164168
return nil
165169
})

internal/config/globalconfig/global_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/commitdev/zero/internal/constants"
1414
"github.com/commitdev/zero/internal/util"
1515
"github.com/commitdev/zero/pkg/util/exit"
16+
"github.com/commitdev/zero/pkg/util/flog"
1617
yaml "gopkg.in/yaml.v2"
1718
)
1819

@@ -140,12 +141,14 @@ func readOrCreateUserCredentialsFile() []byte {
140141
if fileStateErr != nil {
141142
exit.Fatal("Failed to create config file: %v", fileStateErr)
142143
}
144+
flog.Debugf("Created credentials file: %s", credPath)
143145
defer file.Close()
144146
}
145147
data, err := ioutil.ReadFile(credPath)
146148
if err != nil {
147149
exit.Fatal("Failed to read credentials file: %v", err)
148150
}
151+
flog.Debugf("Loaded credentials file: %s", credPath)
149152
return data
150153
}
151154

@@ -166,6 +169,7 @@ func GetProjectCredentials(targetProjectName string) ProjectCredential {
166169
func Save(project ProjectCredential) {
167170
projects := LoadUserCredentials()
168171
projects[project.ProjectName] = project
172+
flog.Debugf("Saved project credentials : %s", project.ProjectName)
169173
writeCredentialsFile(projects)
170174
}
171175

internal/config/projectconfig/init.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/commitdev/zero/internal/constants"
1111
"github.com/commitdev/zero/internal/util"
12+
"github.com/commitdev/zero/pkg/util/flog"
1213
"gopkg.in/yaml.v2"
1314
)
1415

@@ -35,7 +36,9 @@ func CreateProjectConfigFile(dir string, projectName string, projectContext *Zer
3536
return err
3637
}
3738

38-
writeErr := ioutil.WriteFile(path.Join(dir, projectName, constants.ZeroProjectYml), []byte(content), 0644)
39+
filePath := path.Join(dir, projectName, constants.ZeroProjectYml)
40+
flog.Debugf("Project file path: %s", filePath)
41+
writeErr := ioutil.WriteFile(filePath, []byte(content), 0644)
3942
if writeErr != nil {
4043
return err
4144
}

internal/config/projectconfig/project_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io/ioutil"
55
"log"
66

7+
"github.com/commitdev/zero/pkg/util/flog"
78
"github.com/hashicorp/terraform/dag"
89
"github.com/k0kubun/pp"
910
yaml "gopkg.in/yaml.v2"
@@ -45,7 +46,7 @@ func LoadConfig(filePath string) *ZeroProjectConfig {
4546
if err != nil {
4647
log.Panicf("failed to parse config: %v", err)
4748
}
48-
49+
flog.Debugf("Loaded project config: %s from %s", config.Name, filePath)
4950
return config
5051
}
5152

internal/init/prompts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ func executeCmd(command string, envVars map[string]string) string {
154154
cmd := exec.Command("bash", "-c", command)
155155
cmd.Env = util.AppendProjectEnvToCmdEnv(envVars, os.Environ())
156156
out, err := cmd.Output()
157-
157+
flog.Debugf("Running command: %s", command)
158158
if err != nil {
159159
log.Fatalf("Failed to execute %v\n", err)
160160
}
161+
flog.Debugf("Command result: %s", string(out))
161162
return string(out)
162163
}
163164

internal/module/module.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/commitdev/zero/internal/constants"
1414
"github.com/commitdev/zero/internal/util"
1515
"github.com/commitdev/zero/pkg/util/exit"
16+
"github.com/commitdev/zero/pkg/util/flog"
1617
"github.com/hashicorp/go-getter"
1718
)
1819

@@ -22,6 +23,7 @@ func FetchModule(source string, wg *sync.WaitGroup) {
2223

2324
localPath := GetSourceDir(source)
2425
if !IsLocal(source) {
26+
flog.Debugf("Downloading module: %s to %s", source, localPath)
2527
err := getter.Get(localPath, source)
2628
if err != nil {
2729
exit.Fatal("Failed to fetch remote module from %s: %v\n", source, err)

internal/vcs/create-git-repos.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func InitializeRepository(repositoryUrl string, githubApiKey string) {
2020
fmt.Printf("error creating repository: %s\n", err.Error())
2121
return
2222
}
23+
flog.Debugf("Initialized repo: %s/%s", ownerName, repositoryName)
2324

2425
isOrgOwned, ownerId, err := isOrganizationOwned(ownerName, githubApiKey)
2526
if err != nil {
@@ -190,6 +191,7 @@ func doInitialCommit(ownerName string, repositoryName string) error {
190191

191192
cmd := exec.Command(command.command, command.args...)
192193
cmd.Dir = "./" + repositoryName
194+
flog.Debugf("Running (%s) command in %s, %#v", command.command, cmd.Dir, command.args)
193195
_, err := cmd.CombinedOutput()
194196
if err != nil {
195197
fmt.Printf("ERROR: failed to run %s: %s\n", command.description, err.Error())

0 commit comments

Comments
 (0)