fix log usage

This commit is contained in:
ginuerzh
2022-01-26 16:45:57 +08:00
parent 04dfc8c4c3
commit 713586729b
16 changed files with 183 additions and 185 deletions

View File

@ -5,7 +5,6 @@ import (
"net"
"github.com/go-gost/gost/pkg/connector"
"github.com/go-gost/gost/pkg/logger"
md "github.com/go-gost/gost/pkg/metadata"
"github.com/go-gost/gost/pkg/registry"
)
@ -15,18 +14,18 @@ func init() {
}
type sniConnector struct {
md metadata
logger logger.Logger
md metadata
options connector.Options
}
func NewConnector(opts ...connector.Option) connector.Connector {
options := &connector.Options{}
options := connector.Options{}
for _, opt := range opts {
opt(options)
opt(&options)
}
return &sniConnector{
logger: options.Logger,
options: options,
}
}
@ -35,13 +34,13 @@ func (c *sniConnector) Init(md md.Metadata) (err error) {
}
func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, address string, opts ...connector.ConnectOption) (net.Conn, error) {
c.logger = c.logger.WithFields(map[string]interface{}{
log := c.options.Logger.WithFields(map[string]interface{}{
"remote": conn.RemoteAddr().String(),
"local": conn.LocalAddr().String(),
"network": network,
"address": address,
})
c.logger.Infof("connect %s/%s", address, network)
log.Infof("connect %s/%s", address, network)
return &sniClientConn{Conn: conn, host: c.md.host}, nil
}