Use logrus for logging so we can later introduce verbosity levels

This commit is contained in:
Tim Park 2018-12-19 11:17:11 -08:00
Родитель 1505844a74
Коммит f0ab014d83
7 изменённых файлов: 34 добавлений и 11 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import (
"github.com/Microsoft/fabrikate/core"
"github.com/Microsoft/fabrikate/generators"
"github.com/kyokomi/emoji"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@ -41,7 +42,7 @@ func Generate(startPath string, environment string) (components []core.Component
ioutil.WriteFile(componentYAMLFilePath, []byte(component.Manifest), 0644)
}
emoji.Printf(":raised_hands: finished generate\n")
log.Info(emoji.Sprintf(":raised_hands: finished generate"))
return components, err
}

Просмотреть файл

@ -6,12 +6,13 @@ import (
"github.com/Microsoft/fabrikate/core"
"github.com/Microsoft/fabrikate/generators"
"github.com/kyokomi/emoji"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func Install(path string) (err error) {
_, err = core.IterateComponentTree(path, "", func(path string, component *core.Component) (err error) {
emoji.Printf(":point_right: starting install for component: %s\n", component.Name)
log.Info(emoji.Sprintf(":point_right: starting install for component: %s", component.Name))
if err := component.Install(path); err != nil {
return err
}
@ -22,13 +23,13 @@ func Install(path string) (err error) {
}
if err == nil {
emoji.Printf(":clap: finished install for component: %s\n", component.Name)
log.Info(emoji.Sprintf(":point_left: finished install for component: %s", component.Name))
}
return err
})
emoji.Printf(":raised_hands: finished install\n")
log.Info(emoji.Sprintf(":raised_hands: finished install"))
return err
}

Просмотреть файл

@ -5,6 +5,7 @@ import (
"os"
homedir "github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -52,7 +53,7 @@ func initConfig() {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
log.Errorf("Getting home directory failed with: %s\n", err)
os.Exit(1)
}
@ -65,6 +66,6 @@ func initConfig() {
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
log.Debugf("Using config file: %s\n", viper.ConfigFileUsed())
}
}

Просмотреть файл

@ -10,6 +10,7 @@ import (
"github.com/kyokomi/emoji"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
type Component struct {
@ -109,7 +110,7 @@ func (c *Component) Install(componentPath string) (err error) {
return err
}
emoji.Printf(":helicopter: installing component %s with git from %s\n", subcomponent.Name, subcomponent.Source)
log.Println(emoji.Sprintf(":helicopter: installing component %s with git from %s", subcomponent.Name, subcomponent.Source))
if err = exec.Command("git", "clone", subcomponent.Source, subcomponentPath).Run(); err != nil {
return err
}
@ -165,12 +166,19 @@ func IterateComponentTree(startingPath string, environment string, componentIter
completedComponents = append(completedComponents, component)
for _, subcomponent := range component.Subcomponents {
// if subcomponent is inlined, it doesn't need further processing and we are done.
if subcomponent.Source == "" {
continue
}
componentToQueue := Component{
Name: subcomponent.Name,
PhysicalPath: path.Join(component.PhysicalPath, subcomponent.RelativePathTo()),
LogicalPath: path.Join(component.LogicalPath, subcomponent.Name),
Config: component.Config.Subcomponents[subcomponent.Name],
}
log.Debugf("adding subcomponent '%s' to queue with physical path '%s' and logical path '%s'\n", componentToQueue.Name, componentToQueue.PhysicalPath, componentToQueue.LogicalPath)
queue = append(queue, componentToQueue)
}
}

Просмотреть файл

@ -10,6 +10,7 @@ import (
"github.com/Microsoft/fabrikate/core"
"github.com/kyokomi/emoji"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
@ -42,7 +43,7 @@ func AddNamespaceToManifests(manifests string, namespace string) (namespacedMani
}
func GenerateHelmComponent(component *core.Component) (manifest string, err error) {
emoji.Printf(":truck: generating component '%s' with helm with repo %s\n", component.Name, component.Repo)
log.Println(emoji.Sprintf(":truck: generating component '%s' with helm with repo %s", component.Name, component.Repo))
configYaml, err := yaml.Marshal(&component.Config.Config)
if err != nil {
@ -85,6 +86,6 @@ func InstallHelmComponent(component *core.Component) (err error) {
return err
}
emoji.Printf(":helicopter: install helm repo %s for %s into %s\n", component.Repo, component.Name, helmRepoPath)
log.Println(emoji.Sprintf(":helicopter: install helm repo %s for %s into %s", component.Repo, component.Name, helmRepoPath))
return exec.Command("git", "clone", component.Repo, helmRepoPath, "--depth", "1").Run()
}

Просмотреть файл

@ -7,10 +7,11 @@ import (
"github.com/Microsoft/fabrikate/core"
"github.com/kyokomi/emoji"
log "github.com/sirupsen/logrus"
)
func GenerateStaticComponent(component *core.Component) (manifest string, err error) {
emoji.Printf(":truck: generating component '%s' statically from path %s\n", component.Name, component.Path)
log.Println(emoji.Sprintf(":truck: generating component '%s' statically from path %s", component.Name, component.Path))
staticPath := path.Join(component.PhysicalPath, component.Path)
staticFiles, err := ioutil.ReadDir(staticPath)

12
main.go
Просмотреть файл

@ -1,7 +1,17 @@
package main
import "github.com/Microsoft/fabrikate/cmd"
import (
"github.com/Microsoft/fabrikate/cmd"
log "github.com/sirupsen/logrus"
)
func main() {
formatter := new(log.TextFormatter)
formatter.TimestampFormat = "02-01-2006 15:04:05"
formatter.FullTimestamp = true
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
cmd.Execute()
}