more fine-grained log level

This commit is contained in:
ginuerzh
2022-08-18 11:34:57 +08:00
parent 052b8e9468
commit f3f3acd4e1
57 changed files with 262 additions and 242 deletions

View File

@ -39,7 +39,7 @@ func (c *forwardConnector) Connect(ctx context.Context, conn net.Conn, network,
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
return conn, nil
}

View File

@ -49,7 +49,7 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
req := &http.Request{
Method: http.MethodConnect,
@ -87,9 +87,9 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
return nil, err
}
if log.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.TraceLevel) {
dump, _ := httputil.DumpRequest(req, false)
log.Debug(string(dump))
log.Trace(string(dump))
}
if c.md.connectTimeout > 0 {
@ -111,9 +111,9 @@ func (c *httpConnector) Connect(ctx context.Context, conn net.Conn, network, add
// in this case, close body will be blocked, so we leave it untouched.
// defer resp.Body.Close()
if log.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.TraceLevel) {
dump, _ := httputil.DumpResponse(resp, false)
log.Debug(string(dump))
log.Trace(string(dump))
}
if resp.StatusCode != http.StatusOK {

View File

@ -49,7 +49,7 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
v, _ := conn.(md.Metadatable)
if v == nil {
@ -80,9 +80,9 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
"Basic "+base64.StdEncoding.EncodeToString([]byte(u+":"+p)))
}
if log.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.TraceLevel) {
dump, _ := httputil.DumpRequest(req, false)
log.Debug(string(dump))
log.Trace(string(dump))
}
if c.md.connectTimeout > 0 {
@ -98,9 +98,9 @@ func (c *http2Connector) Connect(ctx context.Context, conn net.Conn, network, ad
return nil, err
}
if log.IsLevelEnabled(logger.DebugLevel) {
if log.IsLevelEnabled(logger.TraceLevel) {
dump, _ := httputil.DumpResponse(resp, false)
log.Debug(string(dump))
log.Trace(string(dump))
}
if resp.StatusCode != http.StatusOK {
resp.Body.Close()

View File

@ -20,7 +20,7 @@ func (c *relayConnector) Bind(ctx context.Context, conn net.Conn, network, addre
"network": network,
"address": address,
})
log.Infof("bind on %s/%s", address, network)
log.Debugf("bind on %s/%s", address, network)
options := connector.BindOptions{}
for _, opt := range opts {

View File

@ -44,7 +44,7 @@ func (c *relayConnector) Connect(ctx context.Context, conn net.Conn, network, ad
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
if c.md.connectTimeout > 0 {
conn.SetDeadline(time.Now().Add(c.md.connectTimeout))

View File

@ -40,7 +40,7 @@ func (c *sniConnector) Connect(ctx context.Context, conn net.Conn, network, addr
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
return &sniClientConn{Conn: conn, host: c.md.host}, nil
}

View File

@ -46,7 +46,7 @@ func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, a
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
switch network {
case "tcp", "tcp4", "tcp6":
@ -100,18 +100,18 @@ func (c *socks4Connector) Connect(ctx context.Context, conn net.Conn, network, a
userid = []byte(c.options.Auth.Username())
}
req := gosocks4.NewRequest(gosocks4.CmdConnect, addr, userid)
log.Trace(req)
if err := req.Write(conn); err != nil {
log.Error(err)
return nil, err
}
log.Debug(req)
reply, err := gosocks4.ReadReply(conn)
if err != nil {
log.Error(err)
return nil, err
}
log.Debug(reply)
log.Trace(reply)
if reply.Code != gosocks4.Granted {
err = errors.New("host unreachable")

View File

@ -21,7 +21,7 @@ func (c *socks5Connector) Bind(ctx context.Context, conn net.Conn, network, addr
"network": network,
"address": address,
})
log.Infof("bind on %s/%s", address, network)
log.Debugf("bind on %s/%s", address, network)
options := connector.BindOptions{}
for _, opt := range opts {
@ -98,18 +98,17 @@ func (l *socks5Connector) bind(conn net.Conn, cmd uint8, network, address string
addr := gosocks5.Addr{}
addr.ParseFrom(address)
req := gosocks5.NewRequest(cmd, &addr)
log.Trace(req)
if err := req.Write(conn); err != nil {
return nil, err
}
log.Debug(req)
// first reply, bind status
reply, err := gosocks5.ReadReply(conn)
if err != nil {
return nil, err
}
log.Debug(reply)
log.Trace(reply)
if reply.Rep != gosocks5.Succeeded {
return nil, fmt.Errorf("bind on %s/%s failed", address, network)

View File

@ -93,7 +93,7 @@ func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, a
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
if c.md.connectTimeout > 0 {
conn.SetDeadline(time.Now().Add(c.md.connectTimeout))
@ -122,18 +122,18 @@ func (c *socks5Connector) Connect(ctx context.Context, conn net.Conn, network, a
}
req := gosocks5.NewRequest(gosocks5.CmdConnect, &addr)
log.Trace(req)
if err := req.Write(conn); err != nil {
log.Error(err)
return nil, err
}
log.Debug(req)
reply, err := gosocks5.ReadReply(conn)
if err != nil {
log.Error(err)
return nil, err
}
log.Debug(reply)
log.Trace(reply)
if reply.Rep != gosocks5.Succeeded {
err = errors.New("host unreachable")
@ -156,18 +156,18 @@ func (c *socks5Connector) connectUDP(ctx context.Context, conn net.Conn, network
}
req := gosocks5.NewRequest(socks.CmdUDPTun, nil)
log.Trace(req)
if err := req.Write(conn); err != nil {
log.Error(err)
return nil, err
}
log.Debug(req)
reply, err := gosocks5.ReadReply(conn)
if err != nil {
log.Error(err)
return nil, err
}
log.Debug(reply)
log.Trace(reply)
if reply.Rep != gosocks5.Succeeded {
return nil, errors.New("get socks5 UDP tunnel failure")
@ -178,18 +178,18 @@ func (c *socks5Connector) connectUDP(ctx context.Context, conn net.Conn, network
func (c *socks5Connector) relayUDP(ctx context.Context, conn net.Conn, addr net.Addr, log logger.Logger) (net.Conn, error) {
req := gosocks5.NewRequest(gosocks5.CmdUdp, nil)
log.Trace(req)
if err := req.Write(conn); err != nil {
log.Error(err)
return nil, err
}
log.Debug(req)
reply, err := gosocks5.ReadReply(conn)
if err != nil {
log.Error(err)
return nil, err
}
log.Debug(reply)
log.Trace(reply)
if reply.Rep != gosocks5.Succeeded {
return nil, errors.New("get socks5 UDP tunnel failure")

View File

@ -21,7 +21,7 @@ func (p *tcpListener) Accept() (net.Conn, error) {
if err != nil {
return nil, err
}
p.logger.Debug(rep)
p.logger.Trace(rep)
if rep.Rep != gosocks5.Succeeded {
return nil, fmt.Errorf("peer connect failed")
@ -74,7 +74,7 @@ func (p *tcpMuxListener) getPeerConn(conn net.Conn) (net.Conn, error) {
if err != nil {
return nil, err
}
p.logger.Debug(rep)
p.logger.Trace(rep)
if rep.Rep != gosocks5.Succeeded {
err = fmt.Errorf("peer connect failed")

View File

@ -49,18 +49,18 @@ func (s *clientSelector) OnSelected(method uint8, conn net.Conn) (net.Conn, erro
}
req := gosocks5.NewUserPassRequest(gosocks5.UserPassVer, username, password)
s.logger.Trace(req)
if err := req.Write(conn); err != nil {
s.logger.Error(err)
return nil, err
}
s.logger.Debug(req)
resp, err := gosocks5.ReadUserPassResponse(conn)
if err != nil {
s.logger.Error(err)
return nil, err
}
s.logger.Debug(resp)
s.logger.Trace(resp)
if resp.Status != gosocks5.Succeeded {
return nil, gosocks5.ErrAuthFailure

View File

@ -57,7 +57,7 @@ func (c *ssConnector) Connect(ctx context.Context, conn net.Conn, network, addre
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
switch network {
case "tcp", "tcp4", "tcp6":

View File

@ -56,7 +56,7 @@ func (c *ssuConnector) Connect(ctx context.Context, conn net.Conn, network, addr
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
switch network {
case "udp", "udp4", "udp6":

View File

@ -41,7 +41,7 @@ func (c *sshdConnector) Connect(ctx context.Context, conn net.Conn, network, add
"network": network,
"address": address,
})
log.Infof("connect %s/%s", address, network)
log.Debugf("connect %s/%s", address, network)
cc, ok := conn.(*ssh_util.ClientConn)
if !ok {
@ -65,7 +65,7 @@ func (c *sshdConnector) Bind(ctx context.Context, conn net.Conn, network, addres
"network": network,
"address": address,
})
log.Infof("bind on %s/%s", address, network)
log.Debugf("bind on %s/%s", address, network)
cc, ok := conn.(*ssh_util.ClientConn)
if !ok {