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

Allow disabling logging #85

Closed
wants to merge 2 commits into from
Closed

Allow disabling logging #85

wants to merge 2 commits into from

Conversation

heyLu
Copy link
Contributor

@heyLu heyLu commented Aug 1, 2017

There is now a log package, which wraps the logrus methods used in
oxy. In addition to the methods that are used, there is a .Disable
method that disables logging by sending them to /dev/null.

Fixes #83.

There is now a `log` package, which wraps the `logrus` methods used in
oxy.  In addition to the methods that are used, there is a `.Disable`
method that disables logging by sending them to `/dev/null`.
roundrobin/rr.go Outdated
@@ -86,7 +86,8 @@ func (r *RoundRobin) ServeHTTP(w http.ResponseWriter, req *http.Request) {

if log.GetLevel() >= log.DebugLevel {
//log which backend URL we're sending this request to
log.WithFields(log.Fields{"Request": utils.DumpHttpRequest(req), "ForwardURL": url}).Debugf("vulcand/oxy/roundrobin/rr: Forwarding this request to URL")
//log.WithFields(log.Fields{"Request": utils.DumpHttpRequest(req), "ForwardURL": url}).Debugf("vulcand/oxy/roundrobin/rr: Forwarding this request to URL")
Copy link
Contributor

Choose a reason for hiding this comment

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

mmm, leftover comment

@@ -147,7 +147,8 @@ func (rb *Rebalancer) ServeHTTP(w http.ResponseWriter, req *http.Request) {

if log.GetLevel() >= log.DebugLevel {
//log which backend URL we're sending this request to
log.WithFields(log.Fields{"Request": utils.DumpHttpRequest(req), "ForwardURL": url}).Debugf("vulcand/oxy/roundrobin/rebalancer: Forwarding this request to URL")
//log.WithFields(log.Fields{"Request": utils.DumpHttpRequest(req), "ForwardURL": url}).Debugf("vulcand/oxy/roundrobin/rebalancer: Forwarding this request to URL")
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover code

const DebugLevel = logrus.DebugLevel

func Debugf(format string, args ...interface{}) {
log.Debugf(format, args...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe because of the extra layer, your wrapper will log incorrect lines, you should fix that.
Also I would like to avoid using global variables here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe because of the extra layer, your wrapper will log incorrect lines, you should fix that.

Could you elaborate on that or give an example? Were are simply passing the arguments through.

I got it wrong, you mean line numbers, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I would like to avoid using global variables here.

Not sure how we could do that, apart from reintroducing something like the context logger that was removed in #50.

@archisgore
Copy link

This is something we're facing too. But I have conflicted feelings about setting log settings per-module. Something I always like to rely on when merging a library, is whatever common settings I've linked to, are being honored, and someone downstream isn't able to override them without making it known to me.

In general Logrus could do with a per-package or per-module log setting.

sirupsen/logrus#625

Due to golang's mutable nature, such modifications are very difficult to track down in code.

On the other hand, I also buy into the "You break it, you buy it" paradigm. So you might argue that is the caller's responsibility.

@heyLu
Copy link
Contributor Author

heyLu commented Oct 11, 2017

I think in the end this is not what we want. We're favoring another approach:

I would prefer returning the "context logger" that used to be supported in oxy, which was a field/option settable on the structs. That would allow us to customize the logger, and allow us to set specific log level for oxy.

I prototyped that model, which you can find in the context-logger branch. (This branch only changes the forward package, which is the one that generates the most log messages for us. I could add something similar to the other packages as appropriate.)

Please tell us if you would merge something like that.

@archisgore
Copy link

Yes, I'm in favor of this. Since Oxy is always used as a library, it makes sense for it to not force a global logger. This also means the provided logger override can then apply whatever processing it needs.

@heyLu
Copy link
Contributor Author

heyLu commented Oct 12, 2017

Okay, then let's continue in #93, which has the initial implementation for the forward package.

@heyLu heyLu closed this Oct 12, 2017
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.

None yet

4 participants