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

Commit 31cec23

Browse files
authored
Merge pull request #117 from dlorenc/logrus
Switch to logrus.
2 parents 11e9e28 + 5247238 commit 31cec23

33 files changed

+111
-1668
lines changed

BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ go_library(
1818
visibility = ["//visibility:private"],
1919
deps = [
2020
"//cmd:go_default_library",
21-
"//vendor/github.com/golang/glog:go_default_library",
2221
"//vendor/github.com/pkg/profile:go_default_library",
2322
],
2423
)

Godeps/Godeps.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
http_archive(
22
name = "io_bazel_rules_go",
3-
url = "https://github.com/bazelbuild/rules_go/releases/download/0.5.5/rules_go-0.5.5.tar.gz",
43
sha256 = "ca58b0b856dc95473b93f2228ab117913b82a6617fc0deabd107346e3981522a",
4+
url = "https://github.com/bazelbuild/rules_go/releases/download/0.5.5/rules_go-0.5.5.tar.gz",
55
)
6+
67
load("@io_bazel_rules_go//go:def.bzl", "go_repositories")
78

89
go_repositories()

cmd/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ go_library(
1414
"//pkg/util:go_default_library",
1515
"//util:go_default_library",
1616
"//vendor/github.com/docker/docker/client:go_default_library",
17-
"//vendor/github.com/golang/glog:go_default_library",
17+
"//vendor/github.com/sirupsen/logrus:go_default_library",
1818
"//vendor/github.com/spf13/cobra:go_default_library",
1919
"//vendor/github.com/spf13/pflag:go_default_library",
2020
"//version:go_default_library",

cmd/analyze.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/GoogleCloudPlatform/container-diff/differs"
2626
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
27-
"github.com/golang/glog"
27+
"github.com/sirupsen/logrus"
2828
"github.com/spf13/cobra"
2929
)
3030

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

91-
glog.Info("Retrieving analyses")
91+
fmt.Fprintln(os.Stderr, "Retrieving analyses")
9292
outputResults(analyses)
9393

9494
if save {
95-
glog.Infof("Image was saved at %s", image.FSPath)
95+
logrus.Infof("Image was saved at %s", image.FSPath)
9696
}
9797

9898
return nil

cmd/diff.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"github.com/GoogleCloudPlatform/container-diff/differs"
2727
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
28-
"github.com/golang/glog"
28+
"github.com/sirupsen/logrus"
2929
"github.com/spf13/cobra"
3030
)
3131

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

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

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

8585
prepper, err := getPrepperForImage(imageName)
8686
if err != nil {
87-
glog.Error(err)
87+
logrus.Error(err)
8888
return
8989
}
9090
image, err := prepper.GetImage()
9191
imageMap[imageName] = &image
9292
if err != nil {
93-
glog.Warningf("Diff may be inaccurate: %s", err)
93+
logrus.Warningf("Diff may be inaccurate: %s", err)
9494
}
9595
}(imageArg, imageMap)
9696
}
@@ -101,16 +101,16 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
101101
defer pkgutil.CleanupImage(*imageMap[image2Arg])
102102
}
103103

104+
fmt.Fprintln(os.Stderr, "Computing diffs")
104105
req := differs.DiffRequest{*imageMap[image1Arg], *imageMap[image2Arg], diffTypes}
105106
diffs, err := req.GetDiff()
106107
if err != nil {
107108
return fmt.Errorf("Could not retrieve diff: %s", err)
108109
}
109-
glog.Info("Retrieving diffs")
110110
outputResults(diffs)
111111

112112
if save {
113-
glog.Infof("Images were saved at %s and %s", imageMap[image1Arg].FSPath,
113+
logrus.Infof("Images were saved at %s and %s", imageMap[image1Arg].FSPath,
114114
imageMap[image2Arg].FSPath)
115115
}
116116
return nil

cmd/root.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
"errors"
2121
goflag "flag"
2222
"fmt"
23+
"os"
2324
"sort"
2425
"strings"
2526

2627
"github.com/GoogleCloudPlatform/container-diff/differs"
2728
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2829
"github.com/GoogleCloudPlatform/container-diff/util"
2930
"github.com/docker/docker/client"
30-
"github.com/golang/glog"
31+
"github.com/sirupsen/logrus"
3132
"github.com/spf13/cobra"
3233
"github.com/spf13/pflag"
3334
)
@@ -36,6 +37,8 @@ var json bool
3637
var save bool
3738
var types string
3839

40+
var LogLevel string
41+
3942
type validatefxn func(args []string) error
4043

4144
const (
@@ -54,6 +57,14 @@ To specify a remote image, prefix the image ID with 'remote://', e.g. 'remote://
5457
If no prefix is specified, the local daemon will be checked first.
5558
5659
Tarballs can also be specified by simply providing the path to the .tar, .tar.gz, or .tgz file.`,
60+
PersistentPreRun: func(c *cobra.Command, s []string) {
61+
ll, err := logrus.ParseLevel(LogLevel)
62+
if err != nil {
63+
fmt.Println(err)
64+
os.Exit(1)
65+
}
66+
logrus.SetLevel(ll)
67+
},
5768
}
5869

5970
func outputResults(resultMap map[string]util.Result) {
@@ -72,14 +83,14 @@ func outputResults(resultMap map[string]util.Result) {
7283
} else {
7384
err := result.OutputText(analyzerType)
7485
if err != nil {
75-
glog.Error(err)
86+
logrus.Error(err)
7687
}
7788
}
7889
}
7990
if json {
8091
err := util.JSONify(results)
8192
if err != nil {
82-
glog.Error(err)
93+
logrus.Error(err)
8394
}
8495
}
8596
}
@@ -131,6 +142,7 @@ func getPrepperForImage(image string) (pkgutil.Prepper, error) {
131142
}
132143

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

differs/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ go_library(
1515
deps = [
1616
"//pkg/util:go_default_library",
1717
"//util:go_default_library",
18-
"//vendor/github.com/golang/glog:go_default_library",
18+
"//vendor/github.com/sirupsen/logrus:go_default_library",
1919
],
2020
)
2121

differs/apt_diff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2727
"github.com/GoogleCloudPlatform/container-diff/util"
28-
"github.com/golang/glog"
28+
"github.com/sirupsen/logrus"
2929
)
3030

3131
type AptAnalyzer struct {
@@ -86,7 +86,7 @@ func parseLine(text string, currPackage string, packages map[string]util.Package
8686
return value
8787
case "Version":
8888
if packages[currPackage].Version != "" {
89-
glog.Warningln("Multiple versions of same package detected. Diffing such multi-versioning not yet supported.")
89+
logrus.Warningln("Multiple versions of same package detected. Diffing such multi-versioning not yet supported.")
9090
return currPackage
9191
}
9292
modifiedValue := strings.Replace(value, "+", " ", 1)
@@ -107,7 +107,7 @@ func parseLine(text string, currPackage string, packages map[string]util.Package
107107
var err error
108108
size, err = strconv.ParseInt(value, 10, 64)
109109
if err != nil {
110-
glog.Errorf("Could not get size for %s: %s", currPackage, err)
110+
logrus.Errorf("Could not get size for %s: %s", currPackage, err)
111111
size = -1
112112
}
113113
// Installed-Size is in KB, so we convert it to bytes to keep consistent with the tool's size units

differs/differs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2323
"github.com/GoogleCloudPlatform/container-diff/util"
24-
"github.com/golang/glog"
24+
"github.com/sirupsen/logrus"
2525
)
2626

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

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

differs/node_diff.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2727
"github.com/GoogleCloudPlatform/container-diff/util"
28-
"github.com/golang/glog"
28+
"github.com/sirupsen/logrus"
2929
)
3030

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

@@ -68,7 +68,7 @@ func (a NodeAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]ut
6868
}
6969
packageJSON, err := readPackageJSON(currPackage)
7070
if err != nil {
71-
glog.Warningf("Error reading package JSON at %s: %s\n", currPackage, err)
71+
logrus.Warningf("Error reading package JSON at %s: %s\n", currPackage, err)
7272
return packages, err
7373
}
7474
// Build PackageInfo for this package occurence

differs/pip_diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
2626
"github.com/GoogleCloudPlatform/container-diff/util"
27-
"github.com/golang/glog"
27+
"github.com/sirupsen/logrus"
2828
)
2929

3030
type PipAnalyzer struct {
@@ -97,7 +97,7 @@ func (a PipAnalyzer) getPackages(image pkgutil.Image) (map[string]map[string]uti
9797
} else if i+1 < len(contents) && contents[i+1].Name() == packageName+".py" {
9898
size = contents[i+1].Size()
9999
} else {
100-
glog.Errorf("Could not find Python package %s for corresponding metadata info", packageName)
100+
logrus.Errorf("Could not find Python package %s for corresponding metadata info", packageName)
101101
continue
102102
}
103103
currPackage := util.PackageInfo{Version: version, Size: size}

docker_diff.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ set -e
4646
# ex: image = "@//target/to:image.tar"
4747
# diff_base: Tag or digest in a remote registry you want to diff against
4848
# ex: diff_base = "gcr.io/google-appengine/debian8:latest"
49-
# diff_types: Types flag to pass to container diff
49+
# diff_types: Types flag to pass to container diff
5050
# ex: ["pip", "file"]
5151

5252
docker_diff = rule(
@@ -58,14 +58,14 @@ docker_diff = rule(
5858
),
5959
"diff_base": attr.string(mandatory = True),
6060
"diff_types": attr.string_list(
61-
allow_empty = True,
61+
allow_empty = True,
6262
),
6363
"_container_diff": attr.label(
64-
default = Label("//:container-diff"),
65-
executable = True,
66-
cfg = "host",
64+
default = Label("//:container-diff"),
65+
executable = True,
66+
cfg = "host",
6767
),
6868
},
69-
implementation = _impl,
7069
executable = True,
70+
implementation = _impl,
7171
)

main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"os"
2323

2424
"github.com/GoogleCloudPlatform/container-diff/cmd"
25-
"github.com/golang/glog"
2625
"github.com/pkg/profile"
2726
)
2827

@@ -37,5 +36,4 @@ func main() {
3736
fmt.Println(err)
3837
os.Exit(1)
3938
}
40-
glog.Flush()
4139
}

pkg/util/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ go_library(
2121
"//vendor/github.com/containers/image/types:go_default_library",
2222
"//vendor/github.com/docker/docker/client:go_default_library",
2323
"//vendor/github.com/docker/docker/pkg/system:go_default_library",
24-
"//vendor/github.com/golang/glog:go_default_library",
24+
"//vendor/github.com/sirupsen/logrus:go_default_library",
2525
],
2626
)

pkg/util/daemon_prepper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/containers/image/docker/daemon"
2323

2424
"github.com/docker/docker/client"
25-
"github.com/golang/glog"
25+
"github.com/sirupsen/logrus"
2626
)
2727

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

0 commit comments

Comments
 (0)