replace std log w/ logrus
There still needs to be much more logged with the debug level.
This commit is contained in:
parent
a4bddccb41
commit
fa32839623
4 changed files with 22 additions and 20 deletions
|
@ -2,13 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import (
|
||||||
func rootCmdRun(cmd *cobra.Command, args []string) error {
|
func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
cpuProfilePath, _ := cmd.Flags().GetString("cpuprofile")
|
cpuProfilePath, _ := cmd.Flags().GetString("cpuprofile")
|
||||||
if cpuProfilePath != "" {
|
if cpuProfilePath != "" {
|
||||||
log.Println("enabled CPU profiling to " + cpuProfilePath)
|
log.Infoln("enabled CPU profiling to", cpuProfilePath)
|
||||||
f, err := os.Create(cpuProfilePath)
|
f, err := os.Create(cpuProfilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -42,26 +42,26 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
Addr: cfg.PrometheusAddr,
|
Addr: cfg.PrometheusAddr,
|
||||||
Handler: prometheus.Handler(),
|
Handler: prometheus.Handler(),
|
||||||
}
|
}
|
||||||
log.Println("started serving prometheus stats on", cfg.PrometheusAddr)
|
log.Infoln("started serving prometheus stats on", cfg.PrometheusAddr)
|
||||||
if err := promServer.ListenAndServe(); err != nil {
|
if err := promServer.ListenAndServe(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalln("failed to start prometheus server:", err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Force the compiler to enforce memory against the storage interface.
|
// Force the compiler to enforce memory against the storage interface.
|
||||||
peerStore, err := memory.New(cfg.Storage)
|
peerStore, err := memory.New(cfg.Storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("failed to create memory storage: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
preHooks, postHooks, err := configFile.CreateHooks()
|
preHooks, postHooks, err := configFile.CreateHooks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("failed to create hooks: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
logic := middleware.NewLogic(cfg.Config, peerStore, preHooks, postHooks)
|
logic := middleware.NewLogic(cfg.Config, peerStore, preHooks, postHooks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("failed to create TrackerLogic: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown := make(chan struct{})
|
shutdown := make(chan struct{})
|
||||||
|
@ -74,7 +74,7 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
httpFrontend = httpfrontend.NewFrontend(logic, cfg.HTTPConfig)
|
httpFrontend = httpfrontend.NewFrontend(logic, cfg.HTTPConfig)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Println("started serving HTTP on", cfg.HTTPConfig.Addr)
|
log.Infoln("started serving HTTP on", cfg.HTTPConfig.Addr)
|
||||||
if err := httpFrontend.ListenAndServe(); err != nil {
|
if err := httpFrontend.ListenAndServe(); err != nil {
|
||||||
errChan <- errors.New("failed to cleanly shutdown HTTP frontend: " + err.Error())
|
errChan <- errors.New("failed to cleanly shutdown HTTP frontend: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
udpFrontend = udpfrontend.NewFrontend(logic, cfg.UDPConfig)
|
udpFrontend = udpfrontend.NewFrontend(logic, cfg.UDPConfig)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Println("started serving UDP on", cfg.UDPConfig.Addr)
|
log.Infoln("started serving UDP on", cfg.UDPConfig.Addr)
|
||||||
if err := udpFrontend.ListenAndServe(); err != nil {
|
if err := udpFrontend.ListenAndServe(); err != nil {
|
||||||
errChan <- errors.New("failed to cleanly shutdown UDP frontend: " + err.Error())
|
errChan <- errors.New("failed to cleanly shutdown UDP frontend: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,8 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(jzelinskie): stop hooks here
|
||||||
|
|
||||||
close(errChan)
|
close(errChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -125,7 +127,7 @@ func rootCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
close(shutdown)
|
close(shutdown)
|
||||||
closed = true
|
closed = true
|
||||||
} else {
|
} else {
|
||||||
log.Println(bufErr)
|
log.Infoln(bufErr)
|
||||||
}
|
}
|
||||||
bufErr = err
|
bufErr = err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,6 +18,7 @@ import (
|
||||||
jc "github.com/SermoDigital/jose/crypto"
|
jc "github.com/SermoDigital/jose/crypto"
|
||||||
"github.com/SermoDigital/jose/jws"
|
"github.com/SermoDigital/jose/jws"
|
||||||
"github.com/SermoDigital/jose/jwt"
|
"github.com/SermoDigital/jose/jwt"
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/mendsley/gojwk"
|
"github.com/mendsley/gojwk"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
|
@ -64,7 +64,7 @@ func NewHook(cfg Config) middleware.Hook {
|
||||||
case <-time.After(cfg.JWKUpdateInterval):
|
case <-time.After(cfg.JWKUpdateInterval):
|
||||||
resp, err := http.Get(cfg.JWKSetURL)
|
resp, err := http.Get(cfg.JWKSetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to fetch JWK Set: " + err.Error())
|
log.Errorln("failed to fetch JWK Set: " + err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func NewHook(cfg Config) middleware.Hook {
|
||||||
err = json.NewDecoder(resp.Body).Decode(&parsedJWKs)
|
err = json.NewDecoder(resp.Body).Decode(&parsedJWKs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
log.Println("failed to decode JWK JSON: " + err.Error())
|
log.Errorln("failed to decode JWK JSON: " + err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
@ -81,7 +81,7 @@ func NewHook(cfg Config) middleware.Hook {
|
||||||
for kid, parsedJWK := range parsedJWKs {
|
for kid, parsedJWK := range parsedJWKs {
|
||||||
publicKey, err := parsedJWK.DecodePublicKey()
|
publicKey, err := parsedJWK.DecodePublicKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to decode JWK into public key: " + err.Error())
|
log.Errorln("failed to decode JWK into public key: " + err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
keys[kid] = publicKey
|
keys[kid] = publicKey
|
||||||
|
|
|
@ -4,9 +4,9 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
"github.com/chihaya/chihaya/frontend"
|
"github.com/chihaya/chihaya/frontend"
|
||||||
"github.com/chihaya/chihaya/storage"
|
"github.com/chihaya/chihaya/storage"
|
||||||
|
@ -65,7 +65,7 @@ func (l *Logic) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequ
|
||||||
func (l *Logic) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) {
|
func (l *Logic) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) {
|
||||||
for _, h := range l.postHooks {
|
for _, h := range l.postHooks {
|
||||||
if err := h.HandleAnnounce(ctx, req, resp); err != nil {
|
if err := h.HandleAnnounce(ctx, req, resp); err != nil {
|
||||||
log.Println("chihaya: post-announce hooks failed:", err.Error())
|
log.Errorln("chihaya: post-announce hooks failed:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (l *Logic) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest)
|
||||||
func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) {
|
func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) {
|
||||||
for _, h := range l.postHooks {
|
for _, h := range l.postHooks {
|
||||||
if err := h.HandleScrape(ctx, req, resp); err != nil {
|
if err := h.HandleScrape(ctx, req, resp); err != nil {
|
||||||
log.Println("chihaya: post-scrape hooks failed:", err.Error())
|
log.Errorln("chihaya: post-scrape hooks failed:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,13 @@ package memory
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
"github.com/chihaya/chihaya/storage"
|
"github.com/chihaya/chihaya/storage"
|
||||||
)
|
)
|
||||||
|
@ -53,7 +54,7 @@ func New(cfg Config) (storage.PeerStore, error) {
|
||||||
return
|
return
|
||||||
case <-time.After(cfg.GarbageCollectionInterval):
|
case <-time.After(cfg.GarbageCollectionInterval):
|
||||||
before := time.Now().Add(-cfg.PeerLifetime)
|
before := time.Now().Add(-cfg.PeerLifetime)
|
||||||
log.Println("memory: purging peers with no announces since ", before)
|
log.Debugln("memory: purging peers with no announces since", before)
|
||||||
ps.collectGarbage(before)
|
ps.collectGarbage(before)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,7 +328,6 @@ func (s *peerStore) collectGarbage(cutoff time.Time) error {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("memory: collecting garbage. Cutoff time: %s", cutoff.String())
|
|
||||||
cutoffUnix := cutoff.UnixNano()
|
cutoffUnix := cutoff.UnixNano()
|
||||||
for _, shard := range s.shards {
|
for _, shard := range s.shards {
|
||||||
shard.RLock()
|
shard.RLock()
|
||||||
|
|
Loading…
Add table
Reference in a new issue