Skip to content

Commit

Permalink
Exports ODO_LOG_LEVEL env variable in integration tests (#2595)
Browse files Browse the repository at this point in the history
* Exports ODO_LOG_LEVEL env variable in integration tests

* Turns off ODO_LOG_LEVEL if a valid json flag is passed
  • Loading branch information
mik-dass committed Feb 19, 2020
1 parent 69cc05b commit 265c965
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -32,7 +32,7 @@ jobs:
- &osx-test
stage: Test
name: "Unit test on OSX"
os:
os:
- osx
go_import_path: github.com/openshift/odo
go: "1.13.1"
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -26,6 +26,9 @@ SLOW_SPEC_THRESHOLD := 120
# To enable verbosity export or set env GINKGO_TEST_ARGS like "GINKGO_TEST_ARGS=-v"
GINKGO_TEST_ARGS ?=

# ODO_LOG_LEVEL sets the verbose log level for the make tests
export ODO_LOG_LEVEL ?= 4

# Env variable UNIT_TEST_ARGS is used to get control over enabling test flags along with go test.
# For example:
# To enable verbosity export or set env GINKGO_TEST_ARGS like "GINKGO_TEST_ARGS=-v"
Expand Down
5 changes: 4 additions & 1 deletion cmd/odo/odo.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"os"
"strings"

"github.com/golang/glog"
"github.com/openshift/odo/pkg/log"
Expand Down Expand Up @@ -46,7 +47,9 @@ func main() {
// Override the logging level by the value (if set) by the ODO_LOG_LEVEL env
// The "-v" flag set on command line will take precedence over ODO_LOG_LEVEL env
v := flag.CommandLine.Lookup("v").Value.String()
if level, ok := os.LookupEnv("ODO_LOG_LEVEL"); ok && v == "0" {
// if the json flag is passed and is valid, we don't turn on ODO_LOG_LEVEL
jsonFlagValue := flag.CommandLine.Lookup("o").Value.String()
if level, ok := os.LookupEnv("ODO_LOG_LEVEL"); ok && v == "0" && strings.ToLower(jsonFlagValue) != "json" {
_ = flag.CommandLine.Set("v", level)
}

Expand Down

0 comments on commit 265c965

Please sign in to comment.