Skip to content

Commit

Permalink
DEVPROD-13406: silence patch info logs for JSON output (#8599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimchelly authored Jan 9, 2025
1 parent 57820eb commit 705d8f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (

// ClientVersion is the commandline version string used to control updating
// the CLI. The format is the calendar date (YYYY-MM-DD).
ClientVersion = "2025-01-09"
ClientVersion = "2025-01-09a"

// Agent version to control agent rollover. The format is the calendar date
// (YYYY-MM-DD).
Expand Down
11 changes: 10 additions & 1 deletion operations/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/evergreen-ci/evergreen/util"
"github.com/evergreen-ci/utility"
"github.com/mongodb/grip"
"github.com/mongodb/grip/level"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -120,6 +121,14 @@ func Patch() cli.Command {
Action: func(c *cli.Context) error {
confPath := c.Parent().String(confFlagName)
outputJSON := c.Bool(jsonFlagName)
if outputJSON {
// If outputting the patch data as JSON, suppress any non-error
// logs since the logs won't be in JSON format. Errors should
// still appear so users can diagnose issues.
l := grip.GetSender().Level()
l.Threshold = level.Error
grip.Error(errors.Wrap(grip.SetLevel(l), "increasing log level to suppress non-errors for JSON output"))
}
args := c.Args()
params := &patchParams{
Project: c.String(projectFlagName),
Expand Down Expand Up @@ -257,7 +266,7 @@ func Patch() cli.Command {
continue
}
if err = addModuleToPatch(params, args, conf, newPatch, &module, modulePath); err != nil {
grip.ErrorWhen(!outputJSON, fmt.Sprintf("Error adding module '%s' to patch: %s", module.Name, err))
grip.Errorf("Error adding module '%s' to patch: %s", module.Name, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion operations/patch_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func addModuleToPatch(params *patchParams, args cli.Args, conf *ClientSettings,
if !params.SkipConfirm {
grip.Infof("Using branch '%s' for module '%s'.", module.Branch, module.Name)
if diffData.patchSummary != "" {
fmt.Println(diffData.patchSummary)
grip.Info(diffData.patchSummary)
}
if len(diffData.fullPatch) > 0 {
if !confirm("This is a summary of the module patch to be submitted. Include this module's changes?", true) {
Expand Down
12 changes: 8 additions & 4 deletions operations/patch_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ func (p *patchParams) displayPatch(ac *legacyClient, params outputPatchParams) e
return err
}

grip.InfoWhen(!params.outputJSON, "Patch successfully created.")
grip.Info(patchDisp)
grip.Info("Patch successfully created.")
// This is intentionally using fmt.Println instead of grip because if the
// output is JSON, informational grip logs are suppressed. Using fmt.Println
// ensures the patch output is displayed regardless of logging
// configuration.
fmt.Println(patchDisp)

if len(params.patches) == 1 && p.Browse {
browserCmd, err := findBrowserCommand()
Expand Down Expand Up @@ -236,7 +240,7 @@ func findBrowserCommand() ([]string, error) {
// Performs validation for patch or patch-file
func (p *patchParams) validatePatchCommand(ctx context.Context, conf *ClientSettings, ac *legacyClient, comm client.Communicator) (*model.ProjectRef, error) {
if err := p.loadProject(conf); err != nil {
grip.Warningf("warning - failed to set default project: %v\n", err)
grip.Errorf("failed to resolve project: %s\n", err)
}

// If reusing a previous definition, ignore defaults.
Expand All @@ -245,7 +249,7 @@ func (p *patchParams) validatePatchCommand(ctx context.Context, conf *ClientSett
}

if err := p.loadParameters(conf); err != nil {
grip.Warningf("warning - failed to set default parameters: %v\n", err)
grip.Warningf("warning - failed to set default parameters: %s\n", err)
}

if p.Uncommitted || conf.UncommittedChanges {
Expand Down

0 comments on commit 705d8f6

Please sign in to comment.