style: beautify log

This commit is contained in:
mzz2017 2023-03-30 01:55:56 +08:00
parent b0ddedaade
commit f3b80c977c
5 changed files with 20 additions and 17 deletions

View File

@ -138,8 +138,9 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) {
// Dialer: not alive -> alive.
if index == -NotAlive {
a.log.WithFields(logrus.Fields{
"dialer": dialer.property.Name,
"group": a.dialerGroupName,
}).Infof("[NOT ALIVE --%v-> ALIVE] %v", a.CheckTyp.String(), dialer.property.Name)
}).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{
"dialer": dialer.property.Name,
"group": a.dialerGroupName,
}).Infof("[ALIVE --%v-> NOT ALIVE] %v", a.CheckTyp.String(), dialer.property.Name)
}).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))

View File

@ -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)

View File

@ -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[:]),

View File

@ -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.

View File

@ -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)
}
}