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

Add log package #54

Closed
wants to merge 1 commit into from
Closed

Add log package #54

wants to merge 1 commit into from

Conversation

bufdev
Copy link
Contributor

@bufdev bufdev commented Sep 15, 2015

This is probably not ready to merge (but does pass tests), but is more for discussion as to what to do here.

I generally use other log implementations than glog, and others do too. It is nice to be able to choose an alternative logger, so I added a simple interface here for a Logger that takes care of most functionality. Instead of the V system that glog has, if you like this direction, I can add Debugf/Debugln to somewhat take care of that situation.

The package github.com/gengo/grpc-gateway is currently imported in runtime/mux.go, so that glog is still the default. Probably not the best place for this (again, this PR probably needs work, but wanted initial feedback).

Reason for doing *ln: all logging generally does newlines anyways, or handles newlines, so it makes more sense to me. Also this means that my https://github.com/peter-edge/go-protolog/blob/master/protolog.go#L59 Logger is a drop-in, which is what I want to use this for anyways :)

I did a similar thing for https://github.com/grpc/grpc-go in https://github.com/grpc/grpc-go/tree/master/grpclog

@dmitshur
Copy link
Contributor

Travis CI build is failing because of -logtostderr flag still being present.

In general, I am also not a fan of the glog package being used for logging, I wish it were just the standard Go log package because it's simpler. But I can imagine other people their own preferred log libraries, so having an interface is the only way to allow that.

I think it's fair to follow the same strategy as grpc-go then. That would be consistent.

@bufdev
Copy link
Contributor Author

bufdev commented Sep 15, 2015

Ah yea, I can fix that depending on the owner's feelings on this.

Yeah, there's a few options out there and it's inconsistent. I've started using my own https://go.pedge.io/protolog for structured logging in github.com/pachyderm/pachyderm (which is the initial reason I did this PR, so that logging would be consistent for the pachyderm repository), but I would go as far to say that most people use github.com/Sirupsen/logrus (including github.com/docker/docker), which this Logger interface is a drop-in for https://godoc.org/github.com/Sirupsen/logrus#Logger.

glog is way faster though, for the record...which is why it is nice to have the option :)

@bufdev
Copy link
Contributor Author

bufdev commented Sep 15, 2015

@shurcooL @yugui I put together this https://github.com/peter-edge/go-dlog that might satisfy everyone, this would cover grpc-go too so ping @iamqizhao, we could make this common between both grpc-go and grpc-gateway, which would be a big win. I'll extend the documentation tomorrow morning, but it makes it simple, just `import _ "go.pedge.io/dlog/glog". Thoughts on this?

@yugui
Copy link
Member

yugui commented Sep 15, 2015

Although I'm a fan of glog, I like the overall direction of this PR.

I have some comments on implementation details.

  • I don't want you to add dependency on go-dlog for now.
    It is because I don't want to add much dependency on things which neither grpc-go or protoc-gen-go depends on.
  • Some glog.V(1) logs are too verbose for Info level. How about adding Debug level? Is it too far from grpclog?

@bufdev
Copy link
Contributor Author

bufdev commented Sep 15, 2015

My hope would be I could get both you and @iamqizhao to agree on a common implementation, and I figured dlog might be a good answer haha :) If you add a Debug level to grpclog, it's basically dlog, but dlog makes it easier to bring in other implementations and provides other functionality (tomorrow morning I'd send a pull request to grpc-go with it for consideration).

But honestly it really doesn't matter much to me - dlog clearly only took 30 minutes to put together.

Also of note, I've benchmarked glog via proxy on an interface with protolog, and the difference is not measurable as far as I can see.

@bufdev
Copy link
Contributor Author

bufdev commented Sep 15, 2015

I thought I might have commented on this last night: re: the logging levels

In dlog (or whatever we go with), we could add something like:

package glog // the one in go.pedge.io/dlog/glog

var (
  debugVLevel = 1
)

func SetDebugVLevel(level int32) {
  debugVLevel = level
}

...

func (l *logger) Debug(args ...interface{}) {
  glog.V(debugVLevel).Info(args...)
}

For reference, this is what I'm referring to: https://github.com/peter-edge/go-dlog/blob/master/glog/glog.go

This isn't as nice as having the full functionality of glog, but it does make it easier to abstract the logging package away (which is the goal of this PR :) ).

@yugui
Copy link
Member

yugui commented Nov 4, 2015

Closing this PR due to this reason:

I don't want you to add dependency on go-dlog for now. It is because I don't want to add much dependency on things which neither grpc-go or protoc-gen-go depends on.

and because grpc/grpc-go#341 was closed.

@yugui yugui closed this Nov 4, 2015
@dmitshur dmitshur mentioned this pull request Jan 21, 2016
ithinker1991 pushed a commit to tronprotocol/grpc-gateway that referenced this pull request May 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants