Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Switch to logrus. #117

Merged
merged 2 commits into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//cmd:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/pkg/profile:go_default_library",
],
)
Expand Down
7 changes: 1 addition & 6 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.5.5/rules_go-0.5.5.tar.gz",
sha256 = "ca58b0b856dc95473b93f2228ab117913b82a6617fc0deabd107346e3981522a",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.5.5/rules_go-0.5.5.tar.gz",
)

load("@io_bazel_rules_go//go:def.bzl", "go_repositories")

go_repositories()
2 changes: 1 addition & 1 deletion cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go_library(
"//pkg/util:go_default_library",
"//util:go_default_library",
"//vendor/github.com/docker/docker/client:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//version:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/GoogleCloudPlatform/container-diff/differs"
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -43,7 +43,7 @@ var analyzeCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
if err := analyzeImage(args[0], strings.Split(types, ",")); err != nil {
glog.Error(err)
logrus.Error(err)
os.Exit(1)
}
},
Expand Down Expand Up @@ -88,11 +88,11 @@ func analyzeImage(imageName string, analyzerArgs []string) error {
return fmt.Errorf("Error performing image analysis: %s", err)
}

glog.Info("Retrieving analyses")
fmt.Fprintln(os.Stderr, "Retrieving analyses")
outputResults(analyses)

if save {
glog.Infof("Image was saved at %s", image.FSPath)
logrus.Infof("Image was saved at %s", image.FSPath)
}

return nil
Expand Down
14 changes: 7 additions & 7 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

"github.com/GoogleCloudPlatform/container-diff/differs"
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -44,7 +44,7 @@ var diffCmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
if err := diffImages(args[0], args[1], strings.Split(types, ",")); err != nil {
glog.Error(err)
logrus.Error(err)
os.Exit(1)
}
},
Expand All @@ -71,7 +71,7 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
var wg sync.WaitGroup
wg.Add(2)

glog.Infof("Starting diff on images %s and %s, using differs: %s", image1Arg, image2Arg, diffArgs)
fmt.Fprintf(os.Stderr, "Starting diff on images %s and %s, using differs: %s\n", image1Arg, image2Arg, diffArgs)

imageMap := map[string]*pkgutil.Image{
image1Arg: {},
Expand All @@ -84,13 +84,13 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {

prepper, err := getPrepperForImage(imageName)
if err != nil {
glog.Error(err)
logrus.Error(err)
return
}
image, err := prepper.GetImage()
imageMap[imageName] = &image
if err != nil {
glog.Warningf("Diff may be inaccurate: %s", err)
logrus.Warningf("Diff may be inaccurate: %s", err)
}
}(imageArg, imageMap)
}
Expand All @@ -101,16 +101,16 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
defer pkgutil.CleanupImage(*imageMap[image2Arg])
}

fmt.Fprintln(os.Stderr, "Computing diffs")
req := differs.DiffRequest{*imageMap[image1Arg], *imageMap[image2Arg], diffTypes}
diffs, err := req.GetDiff()
if err != nil {
return fmt.Errorf("Could not retrieve diff: %s", err)
}
glog.Info("Retrieving diffs")
outputResults(diffs)

if save {
glog.Infof("Images were saved at %s and %s", imageMap[image1Arg].FSPath,
logrus.Infof("Images were saved at %s and %s", imageMap[image1Arg].FSPath,
imageMap[image2Arg].FSPath)
}
return nil
Expand Down
18 changes: 15 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"errors"
goflag "flag"
"fmt"
"os"
"sort"
"strings"

"github.com/GoogleCloudPlatform/container-diff/differs"
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/docker/docker/client"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand All @@ -36,6 +37,8 @@ var json bool
var save bool
var types string

var LogLevel string

type validatefxn func(args []string) error

const (
Expand All @@ -54,6 +57,14 @@ To specify a remote image, prefix the image ID with 'remote://', e.g. 'remote://
If no prefix is specified, the local daemon will be checked first.

Tarballs can also be specified by simply providing the path to the .tar, .tar.gz, or .tgz file.`,
PersistentPreRun: func(c *cobra.Command, s []string) {
ll, err := logrus.ParseLevel(LogLevel)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
logrus.SetLevel(ll)
},
}

func outputResults(resultMap map[string]util.Result) {
Expand All @@ -72,14 +83,14 @@ func outputResults(resultMap map[string]util.Result) {
} else {
err := result.OutputText(analyzerType)
if err != nil {
glog.Error(err)
logrus.Error(err)
}
}
}
if json {
err := util.JSONify(results)
if err != nil {
glog.Error(err)
logrus.Error(err)
}
}
}
Expand Down Expand Up @@ -131,6 +142,7 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) {
}

func init() {
RootCmd.PersistentFlags().StringVarP(&LogLevel, "verbosity", "v", "warning", "This flag controls the verbosity of container-diff.")
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
}

Expand Down
2 changes: 1 addition & 1 deletion differs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ go_library(
deps = [
"//pkg/util:go_default_library",
"//util:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)

Expand Down
6 changes: 3 additions & 3 deletions differs/apt_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)

type AptAnalyzer struct {
Expand Down Expand Up @@ -86,7 +86,7 @@ func parseLine(text string, currPackage string, packages map[string]util.Package
return value
case "Version":
if packages[currPackage].Version != "" {
glog.Warningln("Multiple versions of same package detected. Diffing such multi-versioning not yet supported.")
logrus.Warningln("Multiple versions of same package detected. Diffing such multi-versioning not yet supported.")
return currPackage
}
modifiedValue := strings.Replace(value, "+", " ", 1)
Expand All @@ -107,7 +107,7 @@ func parseLine(text string, currPackage string, packages map[string]util.Package
var err error
size, err = strconv.ParseInt(value, 10, 64)
if err != nil {
glog.Errorf("Could not get size for %s: %s", currPackage, err)
logrus.Errorf("Could not get size for %s: %s", currPackage, err)
size = -1
}
// Installed-Size is in KB, so we convert it to bytes to keep consistent with the tool's size units
Expand Down
6 changes: 3 additions & 3 deletions differs/differs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)

type DiffRequest struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (req DiffRequest) GetDiff() (map[string]util.Result, error) {
if diff, err := differ.Diff(img1, img2); err == nil {
results[differ.Name()] = diff
} else {
glog.Errorf("Error getting diff with %s: %s", differ.Name(), err)
logrus.Errorf("Error getting diff with %s: %s", differ.Name(), err)
}
}

Expand All @@ -83,7 +83,7 @@ func (req SingleRequest) GetAnalysis() (map[string]util.Result, error) {
if analysis, err := analyzer.Analyze(img); err == nil {
results[analyzeName] = analysis
} else {
glog.Errorf("Error getting analysis with %s: %s", analyzeName, err)
logrus.Errorf("Error getting analysis with %s: %s", analyzeName, err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions differs/node_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)

type NodeAnalyzer struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ func (a NodeAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]ut
}
layerStems, err := buildNodePaths(path)
if err != nil {
glog.Warningf("Error building JSON paths at %s: %s\n", path, err)
logrus.Warningf("Error building JSON paths at %s: %s\n", path, err)
return packages, err
}

Expand All @@ -68,7 +68,7 @@ func (a NodeAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]ut
}
packageJSON, err := readPackageJSON(currPackage)
if err != nil {
glog.Warningf("Error reading package JSON at %s: %s\n", currPackage, err)
logrus.Warningf("Error reading package JSON at %s: %s\n", currPackage, err)
return packages, err
}
// Build PackageInfo for this package occurence
Expand Down
4 changes: 2 additions & 2 deletions differs/pip_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
"github.com/GoogleCloudPlatform/container-diff/util"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)

type PipAnalyzer struct {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
} else if i+1 < len(contents) && contents[i+1].Name() == packageName+".py" {
size = contents[i+1].Size()
} else {
glog.Errorf("Could not find Python package %s for corresponding metadata info", packageName)
logrus.Errorf("Could not find Python package %s for corresponding metadata info", packageName)
continue
}
currPackage := util.PackageInfo{Version: version, Size: size}
Expand Down
12 changes: 6 additions & 6 deletions docker_diff.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ set -e
# ex: image = "@//target/to:image.tar"
# diff_base: Tag or digest in a remote registry you want to diff against
# ex: diff_base = "gcr.io/google-appengine/debian8:latest"
# diff_types: Types flag to pass to container diff
# diff_types: Types flag to pass to container diff
# ex: ["pip", "file"]

docker_diff = rule(
Expand All @@ -58,14 +58,14 @@ docker_diff = rule(
),
"diff_base": attr.string(mandatory = True),
"diff_types": attr.string_list(
allow_empty = True,
allow_empty = True,
),
"_container_diff": attr.label(
default = Label("//:container-diff"),
executable = True,
cfg = "host",
default = Label("//:container-diff"),
executable = True,
cfg = "host",
),
},
implementation = _impl,
executable = True,
implementation = _impl,
)
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"

"github.com/GoogleCloudPlatform/container-diff/cmd"
"github.com/golang/glog"
"github.com/pkg/profile"
)

Expand All @@ -37,5 +36,4 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
glog.Flush()
}
2 changes: 1 addition & 1 deletion pkg/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ go_library(
"//vendor/github.com/containers/image/types:go_default_library",
"//vendor/github.com/docker/docker/client:go_default_library",
"//vendor/github.com/docker/docker/pkg/system:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
],
)
4 changes: 2 additions & 2 deletions pkg/util/daemon_prepper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/containers/image/docker/daemon"

"github.com/docker/docker/client"
"github.com/golang/glog"
"github.com/sirupsen/logrus"
)

type DaemonPrepper struct {
Expand Down Expand Up @@ -61,7 +61,7 @@ func (p DaemonPrepper) GetConfig() (ConfigSchema, error) {
func (p DaemonPrepper) GetHistory() []ImageHistoryItem {
history, err := p.Client.ImageHistory(context.Background(), p.Source)
if err != nil {
glog.Error("Could not obtain image history for %s: %s", p.Source, err)
logrus.Error("Could not obtain image history for %s: %s", p.Source, err)
}
historyItems := []ImageHistoryItem{}
for _, item := range history {
Expand Down
Loading