root: filter out useless commandConn.CloseWrite warning message

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-01-21 00:36:06 +01:00
parent 14b38a9aa8
commit 278f94a8b6
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
2 changed files with 17 additions and 3 deletions

View File

@ -28,12 +28,24 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
}
}
logrus.AddHook(logutil.NewFilter(
logrus.AddHook(logutil.NewFilter([]logrus.Level{
logrus.DebugLevel,
},
"serving grpc connection",
"stopping session",
"using default config store",
))
// filter out useless commandConn.CloseWrite warning message that can occur
// when listing builder instances with "buildx ls" for those that are
// unreachable: "commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
// https://github.com/docker/cli/blob/3fb4fb83dfb5db0c0753a8316f21aea54dab32c5/cli/connhelper/commandconn/commandconn.go#L203-L214
logrus.AddHook(logutil.NewFilter([]logrus.Level{
logrus.WarnLevel,
},
"commandConn.CloseWrite:",
))
addCommands(cmd, dockerCli)
return cmd
}

View File

@ -7,22 +7,24 @@ import (
"github.com/sirupsen/logrus"
)
func NewFilter(filters ...string) logrus.Hook {
func NewFilter(levels []logrus.Level, filters ...string) logrus.Hook {
dl := logrus.New()
dl.SetOutput(ioutil.Discard)
return &logsFilter{
levels: levels,
filters: filters,
discardLogger: dl,
}
}
type logsFilter struct {
levels []logrus.Level
filters []string
discardLogger *logrus.Logger
}
func (d *logsFilter) Levels() []logrus.Level {
return []logrus.Level{logrus.DebugLevel}
return d.levels
}
func (d *logsFilter) Fire(entry *logrus.Entry) error {