1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-05-25 05:39:06 -04:00

merge log into common log

This commit is contained in:
Darien Raymond
2017-12-19 21:28:12 +01:00
parent 054ceb865d
commit f4c35db968
45 changed files with 297 additions and 406 deletions

View File

@@ -7,7 +7,6 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
@@ -57,7 +56,7 @@ func (d *DokodemoDoor) Network() net.NetworkList {
}
func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn internet.Connection, dispatcher dispatcher.Interface) error {
log.Trace(newError("processing connection from: ", conn.RemoteAddr()).AtDebug())
newError("processing connection from: ", conn.RemoteAddr()).AtDebug().WriteToLog()
dest := net.Destination{
Network: network,
Address: d.address,

View File

@@ -7,7 +7,6 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
@@ -87,7 +86,7 @@ func (h *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
Port: net.Port(server.Port),
}
}
log.Trace(newError("opening connection to ", destination))
newError("opening connection to ", destination).WriteToLog()
input := outboundRay.OutboundInput()
output := outboundRay.OutboundOutput()
@@ -100,7 +99,7 @@ func (h *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
Address: ip,
Port: destination.Port,
}
log.Trace(newError("changing destination to ", destination))
newError("changing destination to ", destination).WriteToLog()
}
}

View File

@@ -12,11 +12,11 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
"v2ray.com/core/common/net"
http_proto "v2ray.com/core/common/protocol/http"
"v2ray.com/core/common/signal"
@@ -127,7 +127,7 @@ Start:
}
}
log.Trace(newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]"))
newError("request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]").WriteToLog()
conn.SetReadDeadline(time.Time{})
defaultPort := net.Port(80)
@@ -142,7 +142,11 @@ Start:
if err != nil {
return newError("malformed proxy host: ", host).AtWarning().Base(err)
}
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
log.Record(&log.AccessMessage{
From: conn.RemoteAddr(),
To: request.URL,
Status: log.AccessAccepted,
})
if strings.ToUpper(request.Method) == "CONNECT" {
return s.handleConnect(ctx, request, reader, conn, dest, dispatcher)
@@ -278,7 +282,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
result = nil
}
} else {
log.Trace(newError("failed to read response from ", request.Host).Base(err).AtWarning())
newError("failed to read response from ", request.Host).Base(err).AtWarning().WriteToLog()
response = &http.Response{
Status: "Service Unavailable",
StatusCode: 503,

View File

@@ -4,7 +4,6 @@ import (
"context"
"v2ray.com/core/app"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
@@ -77,7 +76,7 @@ func (v *Client) Process(ctx context.Context, outboundRay ray.OutboundRay, diale
if err != nil {
return newError("failed to find an available destination").AtWarning().Base(err)
}
log.Trace(newError("tunneling request to ", destination, " via ", server.Destination()))
newError("tunneling request to ", destination, " via ", server.Destination()).WriteToLog()
defer conn.Close()

View File

@@ -6,10 +6,10 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/log"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
@@ -94,30 +94,40 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
request, data, err := DecodeUDPPacket(s.user, payload)
if err != nil {
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Trace(newError("dropping invalid UDP packet from: ", source).Base(err))
log.Access(source, "", log.AccessRejected, err)
newError("dropping invalid UDP packet from: ", source).Base(err).WriteToLog()
log.Record(&log.AccessMessage{
From: source,
To: "",
Status: log.AccessRejected,
Reason: err,
})
}
payload.Release()
continue
}
if request.Option.Has(RequestOptionOneTimeAuth) && s.account.OneTimeAuth == Account_Disabled {
log.Trace(newError("client payload enables OTA but server doesn't allow it"))
newError("client payload enables OTA but server doesn't allow it").WriteToLog()
payload.Release()
continue
}
if !request.Option.Has(RequestOptionOneTimeAuth) && s.account.OneTimeAuth == Account_Enabled {
log.Trace(newError("client payload disables OTA but server forces it"))
newError("client payload disables OTA but server forces it").WriteToLog()
payload.Release()
continue
}
dest := request.Destination()
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, dest, log.AccessAccepted, "")
log.Record(&log.AccessMessage{
From: source,
To: dest,
Status: log.AccessAccepted,
Reason: "",
})
}
log.Trace(newError("tunnelling request to ", dest))
newError("tunnelling request to ", dest).WriteToLog()
ctx = protocol.ContextWithUser(ctx, request.User)
udpServer.Dispatch(ctx, dest, data, func(payload *buf.Buffer) {
@@ -125,7 +135,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection
data, err := EncodeUDPPacket(request, payload.Bytes())
if err != nil {
log.Trace(newError("failed to encode UDP packet").Base(err).AtWarning())
newError("failed to encode UDP packet").Base(err).AtWarning().WriteToLog()
return
}
defer data.Release()
@@ -144,7 +154,12 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
bufferedReader := buf.NewBufferedReader(buf.NewReader(conn))
request, bodyReader, err := ReadTCPSession(s.user, bufferedReader)
if err != nil {
log.Access(conn.RemoteAddr(), "", log.AccessRejected, err)
log.Record(&log.AccessMessage{
From: conn.RemoteAddr(),
To: "",
Status: log.AccessRejected,
Reason: err,
})
return newError("failed to create request from: ", conn.RemoteAddr()).Base(err)
}
conn.SetReadDeadline(time.Time{})
@@ -152,8 +167,13 @@ func (s *Server) handleConnection(ctx context.Context, conn internet.Connection,
bufferedReader.SetBuffered(false)
dest := request.Destination()
log.Access(conn.RemoteAddr(), dest, log.AccessAccepted, "")
log.Trace(newError("tunnelling request to ", dest))
log.Record(&log.AccessMessage{
From: conn.RemoteAddr(),
To: dest,
Status: log.AccessAccepted,
Reason: "",
})
newError("tunnelling request to ", dest).WriteToLog()
ctx = protocol.ContextWithUser(ctx, request.User)

View File

@@ -7,10 +7,10 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/log"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
@@ -85,7 +85,12 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
request, err := session.Handshake(reader, conn)
if err != nil {
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, "", log.AccessRejected, err)
log.Record(&log.AccessMessage{
From: source,
To: "",
Status: log.AccessRejected,
Reason: err,
})
}
return newError("failed to read request").Base(err)
}
@@ -93,9 +98,14 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
if request.Command == protocol.RequestCommandTCP {
dest := request.Destination()
log.Trace(newError("TCP Connect request to ", dest))
newError("TCP Connect request to ", dest).WriteToLog()
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, dest, log.AccessAccepted, "")
log.Record(&log.AccessMessage{
From: source,
To: dest,
Status: log.AccessAccepted,
Reason: "",
})
}
return s.transport(ctx, reader, conn, dest, dispatcher)
@@ -160,7 +170,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
udpServer := udp.NewDispatcher(dispatcher)
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Trace(newError("client UDP connection from ", source))
newError("client UDP connection from ", source).WriteToLog()
}
reader := buf.NewReader(conn)
@@ -174,7 +184,7 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
request, data, err := DecodeUDPPacket(payload.Bytes())
if err != nil {
log.Trace(newError("failed to parse UDP request").Base(err))
newError("failed to parse UDP request").Base(err).WriteToLog()
continue
}
@@ -182,9 +192,14 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
continue
}
log.Trace(newError("send packet to ", request.Destination(), " with ", len(data), " bytes").AtDebug())
newError("send packet to ", request.Destination(), " with ", len(data), " bytes").AtDebug().WriteToLog()
if source, ok := proxy.SourceFromContext(ctx); ok {
log.Access(source, request.Destination, log.AccessAccepted, "")
log.Record(&log.AccessMessage{
From: source,
To: request.Destination,
Status: log.AccessAccepted,
Reason: "",
})
}
dataBuf := buf.New()
@@ -192,12 +207,12 @@ func (v *Server) handleUDPPayload(ctx context.Context, conn internet.Connection,
udpServer.Dispatch(ctx, request.Destination(), dataBuf, func(payload *buf.Buffer) {
defer payload.Release()
log.Trace(newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug())
newError("writing back UDP response with ", payload.Len(), " bytes").AtDebug().WriteToLog()
udpMessage, err := EncodeUDPPacket(request, payload.Bytes())
defer udpMessage.Release()
if err != nil {
log.Trace(newError("failed to write UDP response").AtWarning().Base(err))
newError("failed to write UDP response").AtWarning().Base(err).WriteToLog()
}
conn.Write(udpMessage.Bytes())

View File

@@ -1,7 +1,6 @@
package vmess
import (
"v2ray.com/core/app/log"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/uuid"
@@ -32,7 +31,7 @@ func (a *InternalAccount) Equals(account protocol.Account) bool {
func (a *Account) AsAccount() (protocol.Account, error) {
id, err := uuid.ParseString(a.Id)
if err != nil {
log.Trace(newError("failed to parse ID").Base(err).AtError())
newError("failed to parse ID").Base(err).AtError().WriteToLog()
return nil, err
}
protoID := protocol.NewID(id)

View File

@@ -10,7 +10,6 @@ import (
"golang.org/x/crypto/chacha20poly1305"
"v2ray.com/core/app/log"
"v2ray.com/core/common"
"v2ray.com/core/common/bitmask"
"v2ray.com/core/common/buf"
@@ -64,7 +63,7 @@ func (c *ClientSession) EncodeRequestHeader(header *protocol.RequestHeader, writ
timestamp := protocol.NewTimestampGenerator(protocol.NowTime(), 30)()
account, err := header.User.GetTypedAccount()
if err != nil {
log.Trace(newError("failed to get user account: ", err).AtError())
newError("failed to get user account: ", err).AtError().WriteToLog()
return nil
}
idHash := c.idHash(account.(*vmess.InternalAccount).AnyValidID().Bytes())
@@ -201,7 +200,7 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
defer buffer.Release()
if err := buffer.AppendSupplier(buf.ReadFullFrom(c.responseReader, 4)); err != nil {
log.Trace(newError("failed to read response header").Base(err))
newError("failed to read response header").Base(err).WriteToLog()
return nil, err
}
@@ -218,7 +217,7 @@ func (c *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.Respon
dataLen := int(buffer.Byte(3))
if err := buffer.Reset(buf.ReadFullFrom(c.responseReader, dataLen)); err != nil {
log.Trace(newError("failed to read response command").Base(err))
newError("failed to read response command").Base(err).WriteToLog()
return nil, err
}
command, err := UnmarshalCommand(cmdID, buffer.Bytes())

View File

@@ -10,12 +10,12 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/serial"
@@ -192,8 +192,13 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
if err != nil {
if errors.Cause(err) != io.EOF {
log.Access(connection.RemoteAddr(), "", log.AccessRejected, err)
log.Trace(newError("invalid request from ", connection.RemoteAddr(), ": ", err).AtInfo())
log.Record(&log.AccessMessage{
From: connection.RemoteAddr(),
To: "",
Status: log.AccessRejected,
Reason: err,
})
newError("invalid request from ", connection.RemoteAddr(), ": ", err).AtInfo().WriteToLog()
}
return err
}
@@ -203,11 +208,17 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
request.Port = net.Port(0)
}
log.Access(connection.RemoteAddr(), request.Destination(), log.AccessAccepted, "")
log.Trace(newError("received request for ", request.Destination()))
log.Record(&log.AccessMessage{
From: connection.RemoteAddr(),
To: request.Destination(),
Status: log.AccessAccepted,
Reason: "",
})
newError("received request for ", request.Destination()).WriteToLog()
if err := connection.SetReadDeadline(time.Time{}); err != nil {
log.Trace(newError("unable to set back read deadline").Base(err))
newError("unable to set back read deadline").Base(err).WriteToLog()
}
sessionPolicy = h.policyManager.GetPolicy(request.User.Level)
@@ -254,7 +265,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
if h.inboundHandlerManager != nil {
handler, err := h.inboundHandlerManager.GetHandler(ctx, tag)
if err != nil {
log.Trace(newError("failed to get detour handler: ", tag, err).AtWarning())
newError("failed to get detour handler: ", tag, err).AtWarning().WriteToLog()
return nil
}
proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
@@ -264,7 +275,7 @@ func (h *Handler) generateCommand(ctx context.Context, request *protocol.Request
availableMin = 255
}
log.Trace(newError("pick detour handler for port ", port, " for ", availableMin, " minutes.").AtDebug())
newError("pick detour handler for port ", port, " for ", availableMin, " minutes.").AtDebug().WriteToLog()
user := inboundHandler.GetUser(request.User.Email)
if user == nil {
return nil

View File

@@ -7,7 +7,6 @@ import (
"time"
"v2ray.com/core/app"
"v2ray.com/core/app/log"
"v2ray.com/core/app/policy"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
@@ -80,7 +79,7 @@ func (v *Handler) Process(ctx context.Context, outboundRay ray.OutboundRay, dial
if !ok {
return newError("target not specified").AtError()
}
log.Trace(newError("tunneling request to ", target, " via ", rec.Destination()))
newError("tunneling request to ", target, " via ", rec.Destination()).WriteToLog()
command := protocol.RequestCommandTCP
if target.Network == net.Network_UDP {