Skip to content

Commit

Permalink
Stop logs from going to console by default (istio#446)
Browse files Browse the repository at this point in the history
* Stop logs from going to console by default

* Revert some changes which disabled e2e test output capture
  • Loading branch information
ostromart authored and istio-testing committed Oct 23, 2019
1 parent a426860 commit a5a12d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/mesh/manifest-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func manifestApplyCmd(rootArgs *rootArgs, maArgs *manifestApplyArgs) *cobra.Comm
Long: "The apply subcommand generates an Istio install manifest and applies it to a cluster.",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
// Passing cmd.OutOrStdXXX() allows capturing command output for e2e tests.
l := newLogger(rootArgs.logToStdErr, cmd.OutOrStdout(), cmd.OutOrStderr())
if !maArgs.skipConfirmation && maArgs.kubeConfigPath == "" && maArgs.context == "" {
if !confirm("Do you want to proceed? (y/N)", cmd.OutOrStdout()) {
Expand Down
14 changes: 11 additions & 3 deletions cmd/mesh/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ func initLogsOrExit(args *rootArgs) {

func configLogs(logToStdErr bool) error {
opt := log.DefaultOptions()
if !logToStdErr && logToFile {
if !logToStdErr {
opt.ErrorOutputPaths = []string{"/dev/null"}
opt.OutputPaths = []string{"/dev/null"}
}
if logToFile {
opt.ErrorOutputPaths = []string{logFilePath}
opt.OutputPaths = []string{logFilePath}
}
Expand All @@ -66,6 +70,8 @@ type logger struct {
stdErr io.Writer
}

// newLogger creates a new logger and returns a pointer to it.
// stdOut and stdErr can be used to capture output for testing.
func newLogger(logToStdErr bool, stdOut, stdErr io.Writer) *logger {
return &logger{
logToStdErr: logToStdErr,
Expand All @@ -83,8 +89,9 @@ func (l *logger) logAndPrint(v ...interface{}) {
if !l.logToStdErr {
l.print(s)
l.print("\n")
} else {
log.Infof(s)
}
log.Infof(s)
}

func (l *logger) logAndFatal(v ...interface{}) {
Expand All @@ -97,8 +104,9 @@ func (l *logger) logAndPrintf(format string, a ...interface{}) {
if !l.logToStdErr {
l.print(s)
l.print("\n")
} else {
log.Infof(s)
}
log.Infof(s)
}

func (l *logger) logAndFatalf(format string, a ...interface{}) {
Expand Down

0 comments on commit a5a12d8

Please sign in to comment.