From f3b80c977c38516c7487caacc546612572d64738 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Thu, 30 Mar 2023 01:55:56 +0800 Subject: [PATCH] style: beautify log --- component/outbound/dialer/alive_dialer_set.go | 10 ++++++---- control/connectivity.go | 9 +++++---- control/dns_control.go | 4 ++-- control/tcp.go | 8 ++++---- control/udp.go | 6 +++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/component/outbound/dialer/alive_dialer_set.go b/component/outbound/dialer/alive_dialer_set.go index f7285a8..e221ada 100644 --- a/component/outbound/dialer/alive_dialer_set.go +++ b/component/outbound/dialer/alive_dialer_set.go @@ -138,8 +138,9 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) { // Dialer: not alive -> alive. if index == -NotAlive { a.log.WithFields(logrus.Fields{ - "group": a.dialerGroupName, - }).Infof("[NOT ALIVE --%v-> ALIVE] %v", a.CheckTyp.String(), dialer.property.Name) + "dialer": dialer.property.Name, + "group": a.dialerGroupName, + }).Infof("[NOT ALIVE --%v-> ALIVE]", a.CheckTyp.String()) } a.dialerToIndex[dialer] = len(a.inorderedAliveDialerSet) a.inorderedAliveDialerSet = append(a.inorderedAliveDialerSet, dialer) @@ -149,8 +150,9 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) { if index >= 0 { // Dialer: alive -> not alive. a.log.WithFields(logrus.Fields{ - "group": a.dialerGroupName, - }).Infof("[ALIVE --%v-> NOT ALIVE] %v", a.CheckTyp.String(), dialer.property.Name) + "dialer": dialer.property.Name, + "group": a.dialerGroupName, + }).Infof("[ALIVE --%v-> NOT ALIVE]", a.CheckTyp.String()) // Remove the dialer from inorderedAliveDialerSet. if index >= len(a.inorderedAliveDialerSet) { a.log.Panicf("index:%v >= len(a.inorderedAliveDialerSet):%v", index, len(a.inorderedAliveDialerSet)) diff --git a/control/connectivity.go b/control/connectivity.go index 2781c2e..14c2a75 100644 --- a/control/connectivity.go +++ b/control/connectivity.go @@ -31,12 +31,13 @@ func (c *controlPlaneCore) OutboundAliveChangeCallback(outbound uint8) func(aliv default: } if !isInit || c.log.IsLevelEnabled(logrus.TraceLevel) { + strAlive := "NOT ALIVE" + if alive { + strAlive = "ALIVE" + } c.log.WithFields(logrus.Fields{ - "alive": alive, - "network": networkType.StringWithoutDns(), "outboundId": outbound, - "outbound": c.outboundId2Name[outbound], - }).Warnf("Outbound alive state changed, notify the kernel program.") + }).Warnf("Outbound <%v> %v -> %v, notify the kernel program.", c.outboundId2Name[outbound], networkType.StringWithoutDns(), strAlive) } value := uint32(0) diff --git a/control/dns_control.go b/control/dns_control.go index 8f74291..9efdefc 100644 --- a/control/dns_control.go +++ b/control/dns_control.go @@ -190,7 +190,7 @@ loop: // Update DnsCache. if c.log.IsLevelEnabled(logrus.TraceLevel) { c.log.WithFields(logrus.Fields{ - "qname": q.Name, + "_qname": q.Name, "rcode": msg.RCode, "ans": FormatDnsRsc(msg.Answers), "auth": FormatDnsRsc(msg.Authorities), @@ -571,7 +571,7 @@ func (c *DnsController) dialSend(req *udpRequest, data []byte, id uint16, upstre "outbound": dialArgument.bestOutbound.Name, "policy": dialArgument.bestOutbound.GetSelectionPolicy(), "dialer": dialArgument.bestDialer.Property().Name, - "qname": qname, + "_qname": qname, "qtype": qtype, "pid": req.routingResult.Pid, "pname": ProcessName2String(req.routingResult.Pname[:]), diff --git a/control/tcp.go b/control/tcp.go index 030416c..eec8941 100644 --- a/control/tcp.go +++ b/control/tcp.go @@ -101,19 +101,19 @@ func (c *ControlPlane) handleConn(lConn net.Conn) (err error) { return fmt.Errorf("failed to select dialer from group %v (%v): %w", outbound.Name, networkType.String(), err) } - dialTarget, dialMode := c.ChooseDialTarget(outboundIndex, dst, domain) + dialTarget, _ := c.ChooseDialTarget(outboundIndex, dst, domain) if c.log.IsLevelEnabled(logrus.InfoLevel) { c.log.WithFields(logrus.Fields{ "network": networkType.String(), "outbound": outbound.Name, "policy": outbound.GetSelectionPolicy(), "dialer": d.Property().Name, - "domain": domain, + "sniffed": domain, + "ip": RefineAddrPortToShow(dst), "pid": routingResult.Pid, "pname": ProcessName2String(routingResult.Pname[:]), "mac": Mac2String(routingResult.Mac[:]), - "dialMode": dialMode, - }).Infof("%v <-> %v", RefineSourceToShow(src, dst.Addr(), consts.LanWanFlag_NotApplicable), RefineAddrPortToShow(dst)) + }).Infof("%v <-> %v", RefineSourceToShow(src, dst.Addr(), consts.LanWanFlag_NotApplicable), dialTarget) } // Dial and relay. diff --git a/control/udp.go b/control/udp.go index b0a79ee..7b707ce 100644 --- a/control/udp.go +++ b/control/udp.go @@ -197,7 +197,7 @@ func (c *ControlPlane) handlePkt(lConn *net.UDPConn, data []byte, src, pktDst, r // TODO: Rewritten domain should not use full-cone (such as VMess Packet Addr). // Maybe we should set up a mapping for UDP: Dialer + Target Domain => Remote Resolved IP. // However, games may not use QUIC for communication, thus we cannot use domain to dial, which is fine. - dialTarget, dialMode := c.ChooseDialTarget(outboundIndex, realDst, domain) + dialTarget, _ := c.ChooseDialTarget(outboundIndex, realDst, domain) // Get udp endpoint. var ue *UdpEndpoint @@ -273,12 +273,12 @@ getNew: "policy": outbound.GetSelectionPolicy(), "dialer": ue.Dialer.Property().Name, "domain": domain, + "ip": RefineAddrPortToShow(realDst), "pid": routingResult.Pid, "pname": ProcessName2String(routingResult.Pname[:]), "mac": Mac2String(routingResult.Mac[:]), - "dialMode": dialMode, } - c.log.WithFields(fields).Infof("%v <-> %v", RefineSourceToShow(realSrc, realDst.Addr(), lanWanFlag), RefineAddrPortToShow(realDst)) + c.log.WithFields(fields).Infof("%v <-> %v", RefineSourceToShow(realSrc, realDst.Addr(), lanWanFlag), dialTarget) } }