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
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
2 changes: 1 addition & 1 deletion buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import (
"net/http"

"bufio"
log "github.com/sirupsen/logrus"
"github.com/mailgun/multibuf"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
"net"
"reflect"
Expand Down
3 changes: 1 addition & 2 deletions cbreaker/cbreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"

"github.com/mailgun/timetools"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/memmetrics"
"github.com/vulcand/oxy/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion cbreaker/effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"
"strings"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion cbreaker/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strconv"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion cbreaker/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/predicate"
)

Expand Down
2 changes: 1 addition & 1 deletion cbreaker/ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

log "github.com/sirupsen/logrus"
"github.com/mailgun/timetools"
"github.com/vulcand/oxy/log"
)

// ratioController allows passing portions traffic back to the endpoints,
Expand Down
2 changes: 1 addition & 1 deletion connlimit/connlimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"sync"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion forward/fwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

"crypto/tls"
log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
"net"
"net/http/httputil"
Expand Down
47 changes: 47 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package log

import (
"io/ioutil"

"github.com/Sirupsen/logrus"
)

var log *logrus.Logger

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.

}

func Infof(format string, args ...interface{}) {
log.Infof(format, args...)
}

func Warningf(format string, args ...interface{}) {
log.Warningf(format, args...)
}

func Errorf(format string, args ...interface{}) {
log.Errorf(format, args...)
}

func WithField(key string, value interface{}) *logrus.Entry {
return log.WithField(key, value)
}

func WithFields(fields logrus.Fields) *logrus.Entry {
return log.WithFields(fields)
}

func GetLevel() logrus.Level {
return log.Level
}

func init() {
log = logrus.New()
}

func Disable() {
log.Out = ioutil.Discard
}
2 changes: 1 addition & 1 deletion ratelimit/tokenlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/mailgun/timetools"
"github.com/mailgun/ttlmap"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
4 changes: 2 additions & 2 deletions roundrobin/rebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/mailgun/timetools"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/memmetrics"
"github.com/vulcand/oxy/utils"
)
Expand Down Expand Up @@ -147,7 +147,7 @@ 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.WithField("Request", utils.DumpHttpRequest(req)).WithField("ForwardURL", url).Debugf("vulcand/oxy/roundrobin/rebalancer: Forwarding this request to URL")
}

// make shallow copy of request before changing anything to avoid side effects
Expand Down
4 changes: 2 additions & 2 deletions roundrobin/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"sync"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ 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.WithField("Request", utils.DumpHttpRequest(req)).WithField("ForwardURL", url).Debugf("vulcand/oxy/roundrobin/rr: Forwarding this request to URL")
}

// make shallow copy of request before chaning anything to avoid side effects
Expand Down
2 changes: 1 addition & 1 deletion stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package stream
import (
"net/http"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"time"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
"github.com/vulcand/oxy/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion utils/netutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/url"
"reflect"

log "github.com/sirupsen/logrus"
"github.com/vulcand/oxy/log"
)

// ProxyWriter helps to capture response headers and status code
Expand Down