Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: clean up logging #73

Merged
merged 3 commits into from
Feb 6, 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
26 changes: 14 additions & 12 deletions cmd/umoci/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"time"

"github.com/Sirupsen/logrus"
"github.com/apex/log"
"github.com/cyphar/umoci/mutate"
"github.com/cyphar/umoci/oci/cas"
igen "github.com/cyphar/umoci/oci/generate"
Expand Down Expand Up @@ -279,21 +279,23 @@ func config(ctx *cli.Context) error {
return errors.Wrap(err, "commit mutated image")
}

logrus.WithFields(logrus.Fields{
"mediatype": newDescriptor.MediaType,
"digest": newDescriptor.Digest,
"size": newDescriptor.Size,
}).Infof("created new image")
log.Infof("new image manifest created: %s", newDescriptor.Digest)

// We have to clobber the old reference.
// XXX: Should we output some warning if we actually did remove an old
// reference?
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return errors.Wrap(err, "delete old tag")
err = engine.PutReference(context.Background(), tagName, &newDescriptor)
if err == cas.ErrClobber {
// We have to clobber a tag.
log.Warnf("clobbering existing tag: %s", tagName)

// Delete the old tag.
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return errors.Wrap(err, "delete old tag")
}
err = engine.PutReference(context.Background(), tagName, &newDescriptor)
}
if err := engine.PutReference(context.Background(), tagName, &newDescriptor); err != nil {
if err != nil {
return errors.Wrap(err, "add new tag")
}

log.Infof("created new tag for image manifest: %s", tagName)
return nil
}
6 changes: 2 additions & 4 deletions cmd/umoci/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/apex/log"
"github.com/cyphar/umoci/oci/cas"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -58,8 +58,6 @@ func initLayout(ctx *cli.Context) error {
return errors.Wrap(err, "image layout creation")
}

logrus.WithFields(logrus.Fields{
"path": imagePath,
}).Infof("created new OCI image layout")
log.Infof("created new OCI image: %s", imagePath)
return nil
}
35 changes: 28 additions & 7 deletions cmd/umoci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/apex/log"
logcli "github.com/apex/log/handlers/cli"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -65,14 +66,34 @@ func main() {

app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "set log level to debug",
Name: "verbose",
Usage: "alias for --log=info",
},
cli.StringFlag{
Name: "log",
Usage: "set the log level (debug, info, [warn], error, fatal)",
Value: "warn",
},
}

app.Before = func(ctx *cli.Context) error {
if ctx.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
log.SetHandler(logcli.New(os.Stderr))

if ctx.GlobalBool("verbose") {
if ctx.GlobalIsSet("log") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to no-op on log=info?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to make it so people don't mix the two at all. But thanks for the review.

return errors.New("--log=* and --verbose are mutually exclusive")
}
ctx.GlobalSet("log", "info")
}

level, err := log.ParseLevel(ctx.GlobalString("log"))
if err != nil {
return errors.Wrap(err, "parsing log level")
}

log.SetLevel(level)

if level == log.DebugLevel {
errors.Debug(true)
}
return nil
Expand Down Expand Up @@ -135,8 +156,8 @@ func main() {
// that --rootless might help. We probably should only be doing this if
// we're an unprivileged user.
if os.IsPermission(errors.Cause(err)) {
logrus.Infof("umoci encountered a permission error -- maybe --rootless will help?")
log.Info("umoci encountered a permission error: maybe --rootless will help?")
}
logrus.Fatalf("%v", err)
log.Fatalf("%v", err)
}
}
37 changes: 20 additions & 17 deletions cmd/umoci/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"runtime"
"time"

"github.com/Sirupsen/logrus"
"github.com/apex/log"
"github.com/cyphar/umoci/oci/cas"
igen "github.com/cyphar/umoci/oci/generate"
imeta "github.com/opencontainers/image-spec/specs-go"
Expand Down Expand Up @@ -62,9 +62,9 @@ func newImage(ctx *cli.Context) error {
defer engine.Close()

// Create a new manifest.
logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"tag": tagName,
}).Infof("creating new manifest")
}).Debugf("creating new manifest")

// Create a new image config.
g := igen.New()
Expand All @@ -87,7 +87,7 @@ func newImage(ctx *cli.Context) error {
return errors.Wrap(err, "put config blob")
}

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"digest": configDigest,
"size": configSize,
}).Debugf("umoci: added new config")
Expand All @@ -112,7 +112,7 @@ func newImage(ctx *cli.Context) error {
return errors.Wrap(err, "put manifest blob")
}

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"digest": manifestDigest,
"size": manifestSize,
}).Debugf("umoci: added new manifest")
Expand All @@ -127,21 +127,24 @@ func newImage(ctx *cli.Context) error {
Size: manifestSize,
}

logrus.WithFields(logrus.Fields{
"mediatype": descriptor.MediaType,
"digest": descriptor.Digest,
"size": descriptor.Size,
}).Infof("created new image")

// We have to clobber the old reference.
// XXX: Should we output some warning if we actually did remove an old
// reference?
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return errors.Wrap(err, "delete old tag")
log.Infof("new image manifest created: %s", descriptor.Digest)

err = engine.PutReference(context.Background(), tagName, &descriptor)
if err == cas.ErrClobber {
// We have to clobber a tag.
log.Warnf("clobbering existing tag: %s", tagName)

// Delete the old tag.
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return errors.Wrap(err, "delete old tag")
}
err = engine.PutReference(context.Background(), tagName, &descriptor)
}
if err := engine.PutReference(context.Background(), tagName, &descriptor); err != nil {
if err != nil {
return errors.Wrap(err, "add new tag")
}

log.Infof("created new tag for image manifest: %s", tagName)

return nil
}
38 changes: 21 additions & 17 deletions cmd/umoci/repack.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"
"time"

"github.com/Sirupsen/logrus"
"github.com/apex/log"
"github.com/cyphar/umoci"
"github.com/cyphar/umoci/mutate"
"github.com/cyphar/umoci/oci/cas"
Expand Down Expand Up @@ -89,7 +89,7 @@ func repack(ctx *cli.Context) error {
return errors.Wrap(err, "read umoci.json metadata")
}

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"version": meta.Version,
"from": meta.From,
"map_options": meta.MapOptions,
Expand Down Expand Up @@ -117,7 +117,7 @@ func repack(ctx *cli.Context) error {
mtreePath := filepath.Join(bundlePath, mtreeName+".mtree")
fullRootfsPath := filepath.Join(bundlePath, layer.RootfsName)

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"image": imagePath,
"bundle": bundlePath,
"rootfs": layer.RootfsName,
Expand All @@ -135,7 +135,7 @@ func repack(ctx *cli.Context) error {
return errors.Wrap(err, "parse mtree")
}

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"keywords": MtreeKeywords,
}).Debugf("umoci: parsed mtree spec")

Expand All @@ -144,12 +144,14 @@ func repack(ctx *cli.Context) error {
fsEval = umoci.RootlessFsEval
}

log.Info("computing filesystem diff ...")
diffs, err := mtree.Check(fullRootfsPath, spec, MtreeKeywords, fsEval)
if err != nil {
return errors.Wrap(err, "check mtree")
}
log.Info("... done")

logrus.WithFields(logrus.Fields{
log.WithFields(log.Fields{
"ndiff": len(diffs),
}).Debugf("umoci: checked mtree spec")

Expand Down Expand Up @@ -196,21 +198,23 @@ func repack(ctx *cli.Context) error {
return errors.Wrap(err, "commit mutated image")
}

logrus.WithFields(logrus.Fields{
"mediatype": newDescriptor.MediaType,
"digest": newDescriptor.Digest,
"size": newDescriptor.Size,
}).Infof("created new image")
log.Infof("new image manifest created: %s", newDescriptor.Digest)

// We have to clobber the old reference.
// XXX: Should we output some warning if we actually did remove an old
// reference?
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return err
err = engine.PutReference(context.Background(), tagName, &newDescriptor)
if err == cas.ErrClobber {
// We have to clobber a tag.
log.Warnf("clobbering existing tag: %s", tagName)

// Delete the old tag.
if err := engine.DeleteReference(context.Background(), tagName); err != nil {
return errors.Wrap(err, "delete old tag")
}
err = engine.PutReference(context.Background(), tagName, &newDescriptor)
}
if err := engine.PutReference(context.Background(), tagName, &newDescriptor); err != nil {
return err
if err != nil {
return errors.Wrap(err, "add new tag")
}

log.Infof("created new tag for image manifest: %s", tagName)
return nil
}
3 changes: 3 additions & 0 deletions cmd/umoci/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package main
import (
"fmt"

"github.com/apex/log"
"github.com/cyphar/umoci/oci/cas"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -77,6 +78,7 @@ func tagAdd(ctx *cli.Context) error {
return errors.Wrap(err, "put reference")
}

log.Infof("created new tag: %q -> %q", tagName, fromName)
return nil
}

Expand Down Expand Up @@ -112,6 +114,7 @@ func tagRemove(ctx *cli.Context) error {
return errors.Wrap(err, "delete reference")
}

log.Infof("removed tag: %s", tagName)
return nil
}

Expand Down
Loading