image-tools icon indicating copy to clipboard operation
image-tools copied to clipboard

verbose output

Open xiekeyang opened this issue 9 years ago • 36 comments

close #14 and #22 .

This provides a contexted logger instance, which is exported from logrus, to print the information to stderr and stdout. It level the information through debug option.

Signed-off-by: xiekeyang [email protected]

xiekeyang avatar Oct 21 '16 10:10 xiekeyang

I'd still rather use Fatal instead of Fatalf when the format string is "%s" 1, but other than that 5deb77e looks good to me.

wking avatar Oct 31 '16 04:10 wking

@wking Fix in https://github.com/opencontainers/image-tools/pull/46/commits/7ff9b240279d98f0a3fec661a59981c51ce29da5

  1. logrus.Fatalf("%s",err) -> logrus.Fatal(err)
  2. logrus.Fatalf("constant string") -> logrus.Fatal("constant string")
  3. For error level messages, I keep only using logrus.Errorf(), as I explained in https://github.com/opencontainers/image-tools/pull/46#discussion_r84591679.

xiekeyang avatar Oct 31 '16 06:10 xiekeyang

On Sun, Oct 30, 2016 at 11:20:43PM -0700, xiekeyang wrote:

  1. logrus.Fatalf("%s",err) -> logrus.Fatal(err)
  2. logrus.Fatalf("constant string") -> logrus.Fatal("constant string")
  3. For error level messages, I keep only using logrus.Errorf(), as I explained in https://github.com/opencontainers/image-tools/pull/46#discussion_r84591679.

Errorf vs. Error seems the same as Fatalf vs. Fatal to me. But I'm fine landing this as it stands and filing a follow-up PR to address Errorf → Error in isolation.

wking avatar Oct 31 '16 17:10 wking

@opencontainers/image-tools-maintainers I think this PR may be ready to merged. PTAL.

xiekeyang avatar Nov 18 '16 08:11 xiekeyang

@xiekeyang Make sure that logging is going to stderr to differentiate from problem output, which should go to stdout.

stevvooe avatar Nov 18 '16 20:11 stevvooe

@stevvooe

@xiekeyang Make sure that logging is going to stderr to differentiate from problem output, which should go to stdout.

I assume that problem output means messages consumer want to collect, like why validation failed, right? For example below use stderr,

if err := cmd.Usage(); err != nil {
        logrus.WithError(err).Errorf("usage failed")
}   

And below use stdout.

err := v.validatePath(arg) 
if err != nil { 
  fmt.Printf("error: validation failed: %s",err)
}

Is that what you want to say? If so, I'm not very clear about their difference.

xiekeyang avatar Nov 21 '16 03:11 xiekeyang

@xiekeyang Yes, that is effectively what I am saying. However, the output to stdout should have some machine readable structure.

stevvooe avatar Nov 21 '16 22:11 stevvooe

@stevvooe I mean problem output prompted by validatePath might be open file error, json unmarshal error or so. So, I'm not sure how to differ stderr and stdout and I worry it might loss messages when consumer collect them. I honestly fell they are all stderr. I think they are printed as stderr(to use logrus.WithError(err).Errorf()), and consumer can collect all of them by console or by audit. I have no strong opinion, but could you reconsider it?

xiekeyang avatar Nov 22 '16 02:11 xiekeyang

@stevvooe After read my comment https://github.com/opencontainers/image-tools/pull/46#issuecomment-262130368, do you still want to use stdout to print "problem output", or think to use stderr to be fine? Thanks a lot!

xiekeyang avatar Nov 30 '16 02:11 xiekeyang

@xiekeyang stdout should have only have errors that are part of the program output. For example, if the job of the program is to validate something, the errors in validation would go to standard out. If an error occurs trying to perform the validation, that output would go to stderr.

Simply put, I would print all of logrus to stderr and then control program output through fmt.Printfln or equivalent wrapper.

stevvooe avatar Nov 30 '16 23:11 stevvooe

@stevvooe PTAL https://github.com/opencontainers/image-tools/pull/46/commits/565f138efbfabadff79c3be24bc2b657cbef4bee. Here I fix the stdout and stderr to your proposal, to use logrus for stderr, and go log(Printf and Println) for stdout. I implement the new package logger, to provide public logger structure for each command. If it is what you want? Thanks a lot!

xiekeyang avatar Dec 06 '16 04:12 xiekeyang

Here I fix the stdout and stderr to your proposal, to use logrus for stderr, and go log(Printf and Println) for stdout.

This is not really what I said or meant. :/

There isn't really a point to using both the standard logger and and logrus. They are redundant.

What I said was that you need to differentiate program output, ie. validation, and status of the program with stdout and stderr respectively.

Let's say we have output, tagged with the stream (this is an example, don't add it), it would look like this:

stderr: opened manifest.json for validation
stdout: ok manifest.json
stderr: opened foo.json for validation
stdout: fail foo.json
stdout:   error bad media type
stdout:   error missing digest
stderr: failed to open notexist.json

Typically, we use a logger to write to stderr, which can be logrus to provide leveled logging.

This distinction is the hallmark of a well structured unix tool. It allows us to pipe program output somewhere, while monitoring stderr for behavior.

I hope this clarifies the requirements here. (if anyone else has a link explaining this concept, it would be helpful).

stevvooe avatar Dec 06 '16 20:12 stevvooe

@stevvooe ,

update it in https://github.com/opencontainers/image-tools/pull/46/commits/b619fba6fd9f711de256e3b3bec65e20602a204b.

It should have coverred what you want. PTAL, thanks a lot!

xiekeyang avatar Jan 19 '17 02:01 xiekeyang

And update the PR description at https://github.com/opencontainers/image-tools/pull/46#issue-184446882

xiekeyang avatar Jan 19 '17 12:01 xiekeyang

@stevvooe @vbatts @philips PTAL.

xiekeyang avatar Feb 03 '17 01:02 xiekeyang

LGTM, but rebase is needed

Approved with PullApprove

vbatts avatar Feb 08 '17 19:02 vbatts

rebased, PTAL.

xiekeyang avatar Feb 09 '17 02:02 xiekeyang

LGTM

Approved with PullApprove

vbatts avatar Feb 09 '17 20:02 vbatts

I'm still confused about the role of a full blown logger in a CLI tool. Shouldn't we do something more user friendly?

stevvooe avatar Feb 09 '17 21:02 stevvooe

What is the purpose of this package? However, please let me know what the intent of this package and we can get it into shape. I'm still confused about the role of a full blown logger in a CLI tool. Shouldn't we do something more user friendly?

I'm in progress for this PR. Excuse me that I might only partly understand you. docker/containerd and docker/distribution are using individual, and public package to organize log, and provide an instance. Yes I should wrapped it via go context, for avoiding racing purpose, and we can add more contexts in future. So do you only mean to introduce go context, or you have some another proposal hint? Thanks so much.

xiekeyang avatar Feb 20 '17 11:02 xiekeyang

@stevvooe

What is the purpose of this package? However, please let me know what the intent of this package and we can get it into shape. I'm still confused about the role of a full blown logger in a CLI tool. Shouldn't we do something more user friendly?

I'm in progress for this PR. Excuse me that I might only partly understand you. docker/containerd and docker/distribution are using individual, and public package to organize log, and provide an instance. Yes I should wrapped it via go context, for go racing purpose, and we can add more contexts in future. So do you only mean to introduce go context, or you have some another proposal hint? Thanks so much.

xiekeyang avatar Feb 20 '17 11:02 xiekeyang

@xiekeyang I don't understand why you need a leveled logger in a command line tool. It makes no sense.

stevvooe avatar Feb 22 '17 19:02 stevvooe

@stevvooe You might just want xx-tool -D/--debug. However we note log-level is the way on runtime-tools and docker/containerd repo. I think consumer might have the same case on image-tools. So please reconsider it. Thank lots!

xiekeyang avatar Feb 26 '17 10:02 xiekeyang

docker/containerd repo.

Don't use this as an example: this is very new code and half of it is a daemon.

stevvooe avatar Feb 28 '17 03:02 stevvooe

@stevvooe OK. So I use it as image-tool-xx -D/--debug for logrus.Debugf print. Is that alright?

xiekeyang avatar Feb 28 '17 03:02 xiekeyang

@stevvooe @opencontainers/image-tools-maintainers This is updated.

  1. Logger instance should be retrieved through golang.org/x/net/context.
  2. Set up debug mode for logrus.Debugf(), instead of log-level.
  3. Fire messages to stderr and stdout devices. PTAL, thank lots!

xiekeyang avatar Mar 13 '17 09:03 xiekeyang

i like the idea of using context for sharing the logger

vbatts avatar Mar 13 '17 12:03 vbatts

I also really like it, because it means that the CAS and other functions in umoci that will move here should in principle just be able to use the context logging (I didn't even know you could do that -- which is why I'm stuck with apex in umoci :wink:).

cyphar avatar Mar 13 '17 14:03 cyphar

@opencontainers/image-tools-maintainers It is updated, PTAL, thanks.

xiekeyang avatar Mar 15 '17 02:03 xiekeyang

Seems like a good starting point. Thanks @xiekeyang LGTM

Approved with PullApprove

vbatts avatar Mar 15 '17 14:03 vbatts