mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
Merge pull request #924 from crazy-max/log
root: filter out useless commandConn.CloseWrite warning message
This commit is contained in:
commit
6c69d970f7
@ -28,12 +28,26 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.AddHook(logutil.NewFilter(
|
logrus.SetFormatter(&logutil.Formatter{})
|
||||||
|
|
||||||
|
logrus.AddHook(logutil.NewFilter([]logrus.Level{
|
||||||
|
logrus.DebugLevel,
|
||||||
|
},
|
||||||
"serving grpc connection",
|
"serving grpc connection",
|
||||||
"stopping session",
|
"stopping session",
|
||||||
"using default config store",
|
"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)
|
addCommands(cmd, dockerCli)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -7,22 +7,24 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewFilter(filters ...string) logrus.Hook {
|
func NewFilter(levels []logrus.Level, filters ...string) logrus.Hook {
|
||||||
dl := logrus.New()
|
dl := logrus.New()
|
||||||
dl.SetOutput(ioutil.Discard)
|
dl.SetOutput(ioutil.Discard)
|
||||||
return &logsFilter{
|
return &logsFilter{
|
||||||
|
levels: levels,
|
||||||
filters: filters,
|
filters: filters,
|
||||||
discardLogger: dl,
|
discardLogger: dl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type logsFilter struct {
|
type logsFilter struct {
|
||||||
|
levels []logrus.Level
|
||||||
filters []string
|
filters []string
|
||||||
discardLogger *logrus.Logger
|
discardLogger *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *logsFilter) Levels() []logrus.Level {
|
func (d *logsFilter) Levels() []logrus.Level {
|
||||||
return []logrus.Level{logrus.DebugLevel}
|
return d.levels
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *logsFilter) Fire(entry *logrus.Entry) error {
|
func (d *logsFilter) Fire(entry *logrus.Entry) error {
|
||||||
|
16
util/logutil/format.go
Normal file
16
util/logutil/format.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user