Skip to content

Commit

Permalink
root: simple output format on logrus for parity with cli
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Jan 25, 2022
1 parent 278f94a commit d3e56ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
}
}

logrus.SetFormatter(&logutil.Formatter{})

logrus.AddHook(logutil.NewFilter([]logrus.Level{
logrus.DebugLevel,
},
Expand Down
16 changes: 16 additions & 0 deletions util/logutil/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package logutil

import (
"fmt"
"strings"

"github.com/sirupsen/logrus"
)

type Formatter struct {
logrus.TextFormatter
}

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
return []byte(fmt.Sprintf("%s: %s\n", strings.ToUpper(entry.Level.String()), entry.Message)), nil
}

0 comments on commit d3e56ea

Please sign in to comment.