pkg/log: create wrapper around logrus

This commit is contained in:
Leo Balduf
2017-06-20 14:58:44 +02:00
parent 153ad325b7
commit 8ed171b0ea
13 changed files with 211 additions and 77 deletions
+4 -4
View File
@@ -9,12 +9,12 @@ import (
"net/http"
"time"
log "github.com/Sirupsen/logrus"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
"github.com/chihaya/chihaya/bittorrent"
"github.com/chihaya/chihaya/frontend"
"github.com/chihaya/chihaya/pkg/log"
)
func init() {
@@ -117,7 +117,7 @@ func NewFrontend(logic frontend.TrackerLogic, cfg Config) (*Frontend, error) {
go func() {
if err := f.listenAndServe(); err != nil {
log.Fatal("failed while serving http: " + err.Error())
log.Fatal("failed while serving http", log.Err(err))
}
}()
@@ -230,7 +230,7 @@ func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
log.Errorln("http: unable to determine remote address for scrape:", err)
log.Error("http: unable to determine remote address for scrape", log.Err(err))
WriteError(w, err)
return
}
@@ -241,7 +241,7 @@ func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
} else if len(reqIP) == net.IPv6len { // implies reqIP.To4() == nil
req.AddressFamily = bittorrent.IPv6
} else {
log.Errorln("http: invalid IP: neither v4 nor v6, RemoteAddr was", r.RemoteAddr)
log.Error("http: invalid IP: neither v4 nor v6", log.Fields{"RemoteAddr": r.RemoteAddr})
WriteError(w, ErrInvalidIP)
return
}
+2 -3
View File
@@ -3,10 +3,9 @@ package http
import (
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/chihaya/chihaya/bittorrent"
"github.com/chihaya/chihaya/frontend/http/bencode"
"github.com/chihaya/chihaya/pkg/log"
)
// WriteError communicates an error to a BitTorrent client over HTTP.
@@ -15,7 +14,7 @@ func WriteError(w http.ResponseWriter, err error) error {
if _, clientErr := err.(bittorrent.ClientError); clientErr {
message = err.Error()
} else {
log.Errorf("http: internal error: %s", err)
log.Error("http: internal error", log.Err(err))
}
w.WriteHeader(http.StatusOK)