mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-27 09:48:09 -07:00
pkg/log: create wrapper around logrus
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/frontend"
|
||||
"github.com/chihaya/chihaya/frontend/udp/bytepool"
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
)
|
||||
|
||||
@@ -107,7 +107,7 @@ func NewFrontend(logic frontend.TrackerLogic, cfg Config) (*Frontend, error) {
|
||||
}
|
||||
cfg.PrivateKey = string(pkeyRunes)
|
||||
|
||||
log.Warn("UDP private key was not provided, using generated key: ", cfg.PrivateKey)
|
||||
log.Warn("UDP private key was not provided, using generated key", log.Fields{"key": cfg.PrivateKey})
|
||||
}
|
||||
|
||||
f := &Frontend{
|
||||
@@ -118,7 +118,7 @@ func NewFrontend(logic frontend.TrackerLogic, cfg Config) (*Frontend, error) {
|
||||
|
||||
go func() {
|
||||
if err := f.listenAndServe(); err != nil {
|
||||
log.Fatal("failed while serving udp: " + err.Error())
|
||||
log.Fatal("failed while serving udp", log.Err(err))
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -313,7 +313,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (actionName string
|
||||
} else if len(r.IP) == net.IPv6len { // implies r.IP.To4() == nil
|
||||
req.AddressFamily = bittorrent.IPv6
|
||||
} else {
|
||||
log.Errorln("udp: invalid IP: neither v4 nor v6, IP was", r.IP)
|
||||
log.Error("udp: invalid IP: neither v4 nor v6", log.Fields{"IP": r.IP})
|
||||
WriteError(w, txID, ErrInvalidIP)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user