Skip to content

Commit

Permalink
Change how LogObject treats format argument
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Mar 5, 2019
1 parent f2dfe94 commit cf4e9ef
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/ctl/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func doCreateCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
// we should also make a call to resolve the AMI and write the result, similaraly
// the body of the SSH key can be read

if err := printer.LogObj(logger.Debug, "cfg.json = \\\n", cfg); err != nil {
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n%s\n", cfg); err != nil {
return err
}

Expand Down Expand Up @@ -565,7 +565,7 @@ func doCreateCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri

logger.Success("%s is ready", meta.LogString())

if err := printer.LogObj(logger.Debug, "cfg.json = \\\n", cfg); err != nil {
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n%s\n", cfg); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func doCreateNodeGroups(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg s
return err
}

if err := printer.LogObj(logger.Debug, "cfg.json = \\\n", cfg); err != nil {
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n%s\n", cfg); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/delete/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func doDeleteCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
}

logger.Info("deleting EKS cluster %q", meta.Name)
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n", cfg); err != nil {
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n%s\n", cfg); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/update/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func doUpdateClusterCmd(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg s
return errors.Wrapf(err, "getting VPC configuration for cluster %q", cfg.Metadata.Name)
}

if err := printer.LogObj(logger.Debug, "cfg.json = \\\n", cfg); err != nil {
if err := printer.LogObj(logger.Debug, "cfg.json = \\\n%s\n", cfg); err != nil {
return err
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/printers/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"io"
"strings"

"github.com/kris-nova/logger"

Expand Down Expand Up @@ -52,13 +53,13 @@ func (j *JSONPrinter) PrintObjWithKind(kind string, obj interface{}, writer io.W

// LogObj will print the passed object formatted as JSON to
// the logger.
func (j *JSONPrinter) LogObj(log logger.Logger, prefixFmt string, obj interface{}) error {
func (j *JSONPrinter) LogObj(log logger.Logger, msgFmt string, obj interface{}) error {
b := &bytes.Buffer{}
if err := j.PrintObj(obj, b); err != nil {
return err
}

log(prefixFmt+"%s", b.String())
log(msgFmt, strings.ReplaceAll(b.String(), "%", "%%"))

return nil
}
2 changes: 1 addition & 1 deletion pkg/printers/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type OutputPrinter interface {
PrintObjWithKind(kind string, obj interface{}, writer io.Writer) error
PrintObj(obj interface{}, writer io.Writer) error
LogObj(log logger.Logger, prefixFmt string, obj interface{}) error
LogObj(log logger.Logger, msgFmt string, obj interface{}) error
}

// NewPrinter creates a new printer based in the printer type requested
Expand Down
4 changes: 2 additions & 2 deletions pkg/printers/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func (t *TablePrinter) PrintObjWithKind(kind string, obj interface{}, writer io.

// LogObj will print the passed object formatted as a table to
// the logger.
func (t *TablePrinter) LogObj(log logger.Logger, prefixFmt string, obj interface{}) error {
func (t *TablePrinter) LogObj(log logger.Logger, msgFmt string, obj interface{}) error {
b := &bytes.Buffer{}
if err := t.PrintObj(obj, b); err != nil {
return err
}

log(prefixFmt+"%s", b.String())
log(msgFmt, strings.ReplaceAll(b.String(), "%", "%%"))

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/printers/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package printers
import (
"bytes"
"io"
"strings"

"github.com/kris-nova/logger"

Expand Down Expand Up @@ -51,13 +52,13 @@ func (y *YAMLPrinter) PrintObjWithKind(kind string, obj interface{}, writer io.W

// LogObj will print the passed object formatted as YAML to
// the logger.
func (y *YAMLPrinter) LogObj(log logger.Logger, prefixFmt string, obj interface{}) error {
func (y *YAMLPrinter) LogObj(log logger.Logger, msgFmt string, obj interface{}) error {
b := &bytes.Buffer{}
if err := y.PrintObj(obj, b); err != nil {
return err
}

log(prefixFmt+"%s", b.String())
log(msgFmt, strings.ReplaceAll(b.String(), "%", "%%"))

return nil
}

0 comments on commit cf4e9ef

Please sign in to comment.