mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 11:54:01 +03:00
Intergrate custom logger where applicable
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
type StdLikeLogger interface {
|
||||||
|
Printf(format string, args ...interface{})
|
||||||
|
}
|
||||||
+1
-5
@@ -87,10 +87,6 @@ func (p *Proxy) Shutdown() {
|
|||||||
p.workerPool.Release()
|
p.workerPool.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
type antsLogger struct{}
|
|
||||||
|
|
||||||
func (a antsLogger) Printf(msg string, args ...interface{}) {}
|
|
||||||
|
|
||||||
func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
||||||
switch {
|
switch {
|
||||||
case opts.Network == nil:
|
case opts.Network == nil:
|
||||||
@@ -126,7 +122,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
|||||||
|
|
||||||
pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {
|
pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {
|
||||||
proxy.ServeConn(arg.(net.Conn))
|
proxy.ServeConn(arg.(net.Conn))
|
||||||
}, ants.WithLogger(antsLogger{}))
|
}, ants.WithLogger(opts.Logger.Named("ants")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot initialize a pool: %w", err)
|
return nil, fmt.Errorf("cannot initialize a pool: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -6,14 +6,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/events"
|
"github.com/9seconds/mtg/v2/events"
|
||||||
|
"github.com/9seconds/mtg/v2/logger"
|
||||||
"github.com/9seconds/mtg/v2/mtglib"
|
"github.com/9seconds/mtg/v2/mtglib"
|
||||||
statsd "github.com/smira/go-statsd"
|
statsd "github.com/smira/go-statsd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type statsdFakeLogger struct{}
|
|
||||||
|
|
||||||
func (s statsdFakeLogger) Printf(msg string, args ...interface{}) {}
|
|
||||||
|
|
||||||
type statsdProcessor struct {
|
type statsdProcessor struct {
|
||||||
streams map[string]*streamInfo
|
streams map[string]*streamInfo
|
||||||
client *statsd.Client
|
client *statsd.Client
|
||||||
@@ -92,10 +89,11 @@ func (s StatsdFactory) Make() events.Observer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatsd(address, metricPrefix, tagFormat string) (StatsdFactory, error) {
|
func NewStatsd(address string, log logger.StdLikeLogger,
|
||||||
|
metricPrefix, tagFormat string) (StatsdFactory, error) {
|
||||||
options := []statsd.Option{
|
options := []statsd.Option{
|
||||||
statsd.MetricPrefix(metricPrefix),
|
statsd.MetricPrefix(metricPrefix),
|
||||||
statsd.Logger(statsdFakeLogger{}),
|
statsd.Logger(log),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch strings.ToLower(tagFormat) {
|
switch strings.ToLower(tagFormat) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/events"
|
"github.com/9seconds/mtg/v2/events"
|
||||||
|
"github.com/9seconds/mtg/v2/logger"
|
||||||
"github.com/9seconds/mtg/v2/mtglib"
|
"github.com/9seconds/mtg/v2/mtglib"
|
||||||
"github.com/9seconds/mtg/v2/stats"
|
"github.com/9seconds/mtg/v2/stats"
|
||||||
statsd "github.com/smira/go-statsd"
|
statsd "github.com/smira/go-statsd"
|
||||||
@@ -80,7 +81,8 @@ type StatsdTestSuite struct {
|
|||||||
func (suite *StatsdTestSuite) SetupTest() {
|
func (suite *StatsdTestSuite) SetupTest() {
|
||||||
suite.statsdServer = statsdNewFakeServer()
|
suite.statsdServer = statsdNewFakeServer()
|
||||||
|
|
||||||
factory, err := stats.NewStatsd(suite.statsdServer.Addr(), "mtg.", "datadog")
|
factory, err := stats.NewStatsd(suite.statsdServer.Addr(),
|
||||||
|
logger.NewNoopLogger(), "mtg.", "datadog")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user