mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 13:37:08 +08:00
root: filter out useless debug logs from vendored packages
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@ -4,9 +4,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
|
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
|
||||||
|
"github.com/docker/buildx/util/logutil"
|
||||||
"github.com/docker/cli-docs-tool/annotation"
|
"github.com/docker/cli-docs-tool/annotation"
|
||||||
"github.com/docker/cli/cli-plugins/plugin"
|
"github.com/docker/cli/cli-plugins/plugin"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
@ -26,6 +28,12 @@ func NewRootCmd(name string, isPlugin bool, dockerCli command.Cli) *cobra.Comman
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.AddHook(logutil.NewFilter(
|
||||||
|
"serving grpc connection",
|
||||||
|
"stopping session",
|
||||||
|
"using default config store",
|
||||||
|
))
|
||||||
|
|
||||||
addCommands(cmd, dockerCli)
|
addCommands(cmd, dockerCli)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
36
util/logutil/filter.go
Normal file
36
util/logutil/filter.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package logutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewFilter(filters ...string) logrus.Hook {
|
||||||
|
dl := logrus.New()
|
||||||
|
dl.SetOutput(ioutil.Discard)
|
||||||
|
return &logsFilter{
|
||||||
|
filters: filters,
|
||||||
|
discardLogger: dl,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type logsFilter struct {
|
||||||
|
filters []string
|
||||||
|
discardLogger *logrus.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *logsFilter) Levels() []logrus.Level {
|
||||||
|
return []logrus.Level{logrus.DebugLevel}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *logsFilter) Fire(entry *logrus.Entry) error {
|
||||||
|
for _, f := range d.filters {
|
||||||
|
if strings.Contains(entry.Message, f) {
|
||||||
|
entry.Logger = d.discardLogger
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Reference in New Issue
Block a user