Skip to content

Commit

Permalink
initializing logger in persistent pre run, reinitializing after loadi…
Browse files Browse the repository at this point in the history
…ng environment, #1387
  • Loading branch information
nehashri committed Apr 19, 2019
1 parent 0438b7d commit 96c2695
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ go:
addons:
apt:
packages:
- oracle-java8-set-default
- default-jdk
env:
- GAUGE_PREFIX="/tmp/gauge" GAUGE_TELEMETRY_ENABLED=false
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export JAVA_HOME="/usr/lib/jvm/java-8-oracle"; fi
script:
- go run build/make.go
- go run build/make.go --test
Expand Down
3 changes: 2 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
},
DisableAutoGenTag: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
initLogger(cmd.Name())
skel.CreateSkelFilesIfRequired()
track.Init()
config.SetProjectRoot(args)
Expand Down Expand Up @@ -215,7 +216,7 @@ var exit = func(err error, additionalText string) {
os.Exit(0)
}

func loadEnvAndInitLogger(cmd *cobra.Command) {
func loadEnvAndReinitLogger(cmd *cobra.Command) {
if e := env.LoadEnv(environment); e != nil {
logger.Fatalf(true, e.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
if err := config.SetProjectRoot(args); err != nil {
exit(err, cmd.UsageString())
}
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
manifest, _ := manifest.ProjectManifest()
language := manifest.Language
if lsp {
Expand Down
2 changes: 1 addition & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var docsCmd = &cobra.Command{
Long: `Generate documentation using specified plugin.`,
Example: " gauge docs spectacle specs/",
Run: func(cmd *cobra.Command, args []string) {
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
if err := config.SetProjectRoot(args); err != nil {
exit(err, cmd.UsageString())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var formatCmd = &cobra.Command{
Long: `Formats the specified spec files.`,
Example: " gauge format specs/",
Run: func(cmd *cobra.Command, args []string) {
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
if err := config.SetProjectRoot(args); err != nil {
exit(err, cmd.UsageString())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/refactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var refactorCmd = &cobra.Command{
Long: `Refactor steps.`,
Example: ` gauge refactor "old step" "new step"`,
Run: func(cmd *cobra.Command, args []string) {
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
if len(args) < 2 {
exit(fmt.Errorf("Refactor command needs at least two arguments."), cmd.UsageString())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func installMissingPlugins(flag bool) {
}

func execute(cmd *cobra.Command, args []string) {
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
if parallel && tagsToFilterForParallelRun != "" && !env.AllowFilteredParallelExecution() {
logger.Fatal(true, "Filtered parallel execution is a experimental feature. It can be enabled via allow_filtered_parallel_execution property.")
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
"github.com/spf13/cobra"
)

var path = ""
var projectPath = ""

func before() {
path, _ = filepath.Abs("_testData")
config.ProjectRoot = path
projectPath, _ = filepath.Abs("_testData")
config.ProjectRoot = projectPath
}

func after() {
os.RemoveAll(path)
os.RemoveAll(projectPath)
}

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -416,6 +416,7 @@ func TestLogLevelCanBeOverriddenForRepeat(t *testing.T) {
func TestCorrectFlagsAreSetForRepeat(t *testing.T) {
if os.Getenv("TEST_EXITS") == "1" {
// expect "env" to be set to "test"
os.MkdirAll(filepath.Join(projectPath, "env", "test"), 0755)
execution.ExecuteSpecs = func(s []string) int {
f, err := runCmd.Flags().GetString(environmentName)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
Long: `Check for validation and parse errors.`,
Example: " gauge validate specs/",
Run: func(cmd *cobra.Command, args []string) {
loadEnvAndInitLogger(cmd)
loadEnvAndReinitLogger(cmd)
validation.HideSuggestion = hideSuggestion
if err := config.SetProjectRoot(args); err != nil {
exit(err, cmd.UsageString())
Expand Down

0 comments on commit 96c2695

Please sign in to comment.