Skip to content

Commit 43ba7bd

Browse files
authored
use new log package (fatedier#4054)
1 parent 49443cb commit 43ba7bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+389
-405
lines changed

client/admin_api.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
7676
strictConfigMode, _ = strconv.ParseBool(strictStr)
7777
}
7878

79-
log.Info("api request [/api/reload]")
79+
log.Infof("api request [/api/reload]")
8080
defer func() {
81-
log.Info("api response [/api/reload], code [%d]", res.Code)
81+
log.Infof("api response [/api/reload], code [%d]", res.Code)
8282
w.WriteHeader(res.Code)
8383
if len(res.Msg) > 0 {
8484
_, _ = w.Write([]byte(res.Msg))
@@ -89,32 +89,32 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
8989
if err != nil {
9090
res.Code = 400
9191
res.Msg = err.Error()
92-
log.Warn("reload frpc proxy config error: %s", res.Msg)
92+
log.Warnf("reload frpc proxy config error: %s", res.Msg)
9393
return
9494
}
9595
if _, err := validation.ValidateAllClientConfig(cliCfg, proxyCfgs, visitorCfgs); err != nil {
9696
res.Code = 400
9797
res.Msg = err.Error()
98-
log.Warn("reload frpc proxy config error: %s", res.Msg)
98+
log.Warnf("reload frpc proxy config error: %s", res.Msg)
9999
return
100100
}
101101

102102
if err := svr.UpdateAllConfigurer(proxyCfgs, visitorCfgs); err != nil {
103103
res.Code = 500
104104
res.Msg = err.Error()
105-
log.Warn("reload frpc proxy config error: %s", res.Msg)
105+
log.Warnf("reload frpc proxy config error: %s", res.Msg)
106106
return
107107
}
108-
log.Info("success reload conf")
108+
log.Infof("success reload conf")
109109
}
110110

111111
// POST /api/stop
112112
func (svr *Service) apiStop(w http.ResponseWriter, _ *http.Request) {
113113
res := GeneralResponse{Code: 200}
114114

115-
log.Info("api request [/api/stop]")
115+
log.Infof("api request [/api/stop]")
116116
defer func() {
117-
log.Info("api response [/api/stop], code [%d]", res.Code)
117+
log.Infof("api response [/api/stop], code [%d]", res.Code)
118118
w.WriteHeader(res.Code)
119119
if len(res.Msg) > 0 {
120120
_, _ = w.Write([]byte(res.Msg))
@@ -165,9 +165,9 @@ func (svr *Service) apiStatus(w http.ResponseWriter, _ *http.Request) {
165165
res StatusResp = make(map[string][]ProxyStatusResp)
166166
)
167167

168-
log.Info("Http request [/api/status]")
168+
log.Infof("Http request [/api/status]")
169169
defer func() {
170-
log.Info("Http response [/api/status]")
170+
log.Infof("Http response [/api/status]")
171171
buf, _ = json.Marshal(&res)
172172
_, _ = w.Write(buf)
173173
}()
@@ -198,9 +198,9 @@ func (svr *Service) apiStatus(w http.ResponseWriter, _ *http.Request) {
198198
func (svr *Service) apiGetConfig(w http.ResponseWriter, _ *http.Request) {
199199
res := GeneralResponse{Code: 200}
200200

201-
log.Info("Http get request [/api/config]")
201+
log.Infof("Http get request [/api/config]")
202202
defer func() {
203-
log.Info("Http get response [/api/config], code [%d]", res.Code)
203+
log.Infof("Http get response [/api/config], code [%d]", res.Code)
204204
w.WriteHeader(res.Code)
205205
if len(res.Msg) > 0 {
206206
_, _ = w.Write([]byte(res.Msg))
@@ -210,15 +210,15 @@ func (svr *Service) apiGetConfig(w http.ResponseWriter, _ *http.Request) {
210210
if svr.configFilePath == "" {
211211
res.Code = 400
212212
res.Msg = "frpc has no config file path"
213-
log.Warn("%s", res.Msg)
213+
log.Warnf("%s", res.Msg)
214214
return
215215
}
216216

217217
content, err := os.ReadFile(svr.configFilePath)
218218
if err != nil {
219219
res.Code = 400
220220
res.Msg = err.Error()
221-
log.Warn("load frpc config file error: %s", res.Msg)
221+
log.Warnf("load frpc config file error: %s", res.Msg)
222222
return
223223
}
224224
res.Msg = string(content)
@@ -228,9 +228,9 @@ func (svr *Service) apiGetConfig(w http.ResponseWriter, _ *http.Request) {
228228
func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
229229
res := GeneralResponse{Code: 200}
230230

231-
log.Info("Http put request [/api/config]")
231+
log.Infof("Http put request [/api/config]")
232232
defer func() {
233-
log.Info("Http put response [/api/config], code [%d]", res.Code)
233+
log.Infof("Http put response [/api/config], code [%d]", res.Code)
234234
w.WriteHeader(res.Code)
235235
if len(res.Msg) > 0 {
236236
_, _ = w.Write([]byte(res.Msg))
@@ -242,21 +242,21 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
242242
if err != nil {
243243
res.Code = 400
244244
res.Msg = fmt.Sprintf("read request body error: %v", err)
245-
log.Warn("%s", res.Msg)
245+
log.Warnf("%s", res.Msg)
246246
return
247247
}
248248

249249
if len(body) == 0 {
250250
res.Code = 400
251251
res.Msg = "body can't be empty"
252-
log.Warn("%s", res.Msg)
252+
log.Warnf("%s", res.Msg)
253253
return
254254
}
255255

256256
if err := os.WriteFile(svr.configFilePath, body, 0o644); err != nil {
257257
res.Code = 500
258258
res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)
259-
log.Warn("%s", res.Msg)
259+
log.Warnf("%s", res.Msg)
260260
return
261261
}
262262
}

client/connector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *defaultConnectorImpl) Open() error {
8484
tlsConfig, err = transport.NewClientTLSConfig("", "", "", sn)
8585
}
8686
if err != nil {
87-
xl.Warn("fail to build tls configuration, err: %v", err)
87+
xl.Warnf("fail to build tls configuration, err: %v", err)
8888
return err
8989
}
9090
tlsConfig.NextProtos = []string{"frp"}
@@ -164,14 +164,14 @@ func (c *defaultConnectorImpl) realConnect() (net.Conn, error) {
164164
c.cfg.Transport.TLS.TrustedCaFile,
165165
sn)
166166
if err != nil {
167-
xl.Warn("fail to build tls configuration, err: %v", err)
167+
xl.Warnf("fail to build tls configuration, err: %v", err)
168168
return nil, err
169169
}
170170
}
171171

172172
proxyType, addr, auth, err := libdial.ParseProxyURL(c.cfg.Transport.ProxyURL)
173173
if err != nil {
174-
xl.Error("fail to parse proxy url")
174+
xl.Errorf("fail to parse proxy url")
175175
return nil, err
176176
}
177177
dialOptions := []libdial.DialOption{}

client/control.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,32 @@ func (ctl *Control) handleReqWorkConn(_ msg.Message) {
124124
xl := ctl.xl
125125
workConn, err := ctl.connectServer()
126126
if err != nil {
127-
xl.Warn("start new connection to server error: %v", err)
127+
xl.Warnf("start new connection to server error: %v", err)
128128
return
129129
}
130130

131131
m := &msg.NewWorkConn{
132132
RunID: ctl.sessionCtx.RunID,
133133
}
134134
if err = ctl.sessionCtx.AuthSetter.SetNewWorkConn(m); err != nil {
135-
xl.Warn("error during NewWorkConn authentication: %v", err)
135+
xl.Warnf("error during NewWorkConn authentication: %v", err)
136136
workConn.Close()
137137
return
138138
}
139139
if err = msg.WriteMsg(workConn, m); err != nil {
140-
xl.Warn("work connection write to server error: %v", err)
140+
xl.Warnf("work connection write to server error: %v", err)
141141
workConn.Close()
142142
return
143143
}
144144

145145
var startMsg msg.StartWorkConn
146146
if err = msg.ReadMsgInto(workConn, &startMsg); err != nil {
147-
xl.Trace("work connection closed before response StartWorkConn message: %v", err)
147+
xl.Tracef("work connection closed before response StartWorkConn message: %v", err)
148148
workConn.Close()
149149
return
150150
}
151151
if startMsg.Error != "" {
152-
xl.Error("StartWorkConn contains error: %s", startMsg.Error)
152+
xl.Errorf("StartWorkConn contains error: %s", startMsg.Error)
153153
workConn.Close()
154154
return
155155
}
@@ -165,9 +165,9 @@ func (ctl *Control) handleNewProxyResp(m msg.Message) {
165165
// Start a new proxy handler if no error got
166166
err := ctl.pm.StartProxy(inMsg.ProxyName, inMsg.RemoteAddr, inMsg.Error)
167167
if err != nil {
168-
xl.Warn("[%s] start error: %v", inMsg.ProxyName, err)
168+
xl.Warnf("[%s] start error: %v", inMsg.ProxyName, err)
169169
} else {
170-
xl.Info("[%s] start proxy success", inMsg.ProxyName)
170+
xl.Infof("[%s] start proxy success", inMsg.ProxyName)
171171
}
172172
}
173173

@@ -178,7 +178,7 @@ func (ctl *Control) handleNatHoleResp(m msg.Message) {
178178
// Dispatch the NatHoleResp message to the related proxy.
179179
ok := ctl.msgTransporter.DispatchWithType(inMsg, msg.TypeNameNatHoleResp, inMsg.TransactionID)
180180
if !ok {
181-
xl.Trace("dispatch NatHoleResp message to related proxy error")
181+
xl.Tracef("dispatch NatHoleResp message to related proxy error")
182182
}
183183
}
184184

@@ -187,12 +187,12 @@ func (ctl *Control) handlePong(m msg.Message) {
187187
inMsg := m.(*msg.Pong)
188188

189189
if inMsg.Error != "" {
190-
xl.Error("Pong message contains error: %s", inMsg.Error)
190+
xl.Errorf("Pong message contains error: %s", inMsg.Error)
191191
ctl.closeSession()
192192
return
193193
}
194194
ctl.lastPong.Store(time.Now())
195-
xl.Debug("receive heartbeat from server")
195+
xl.Debugf("receive heartbeat from server")
196196
}
197197

198198
// closeSession closes the control connection.
@@ -241,10 +241,10 @@ func (ctl *Control) heartbeatWorker() {
241241
if ctl.sessionCtx.Common.Transport.HeartbeatInterval > 0 {
242242
// send heartbeat to server
243243
sendHeartBeat := func() (bool, error) {
244-
xl.Debug("send heartbeat to server")
244+
xl.Debugf("send heartbeat to server")
245245
pingMsg := &msg.Ping{}
246246
if err := ctl.sessionCtx.AuthSetter.SetPing(pingMsg); err != nil {
247-
xl.Warn("error during ping authentication: %v, skip sending ping message", err)
247+
xl.Warnf("error during ping authentication: %v, skip sending ping message", err)
248248
return false, err
249249
}
250250
_ = ctl.msgDispatcher.Send(pingMsg)
@@ -269,7 +269,7 @@ func (ctl *Control) heartbeatWorker() {
269269

270270
go wait.Until(func() {
271271
if time.Since(ctl.lastPong.Load().(time.Time)) > time.Duration(ctl.sessionCtx.Common.Transport.HeartbeatTimeout)*time.Second {
272-
xl.Warn("heartbeat timeout")
272+
xl.Warnf("heartbeat timeout")
273273
ctl.closeSession()
274274
return
275275
}

client/health/health.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,17 @@ func (monitor *Monitor) checkWorker() {
112112
}
113113

114114
if err == nil {
115-
xl.Trace("do one health check success")
115+
xl.Tracef("do one health check success")
116116
if !monitor.statusOK && monitor.statusNormalFn != nil {
117-
xl.Info("health check status change to success")
117+
xl.Infof("health check status change to success")
118118
monitor.statusOK = true
119119
monitor.statusNormalFn()
120120
}
121121
} else {
122-
xl.Warn("do one health check failed: %v", err)
122+
xl.Warnf("do one health check failed: %v", err)
123123
monitor.failedTimes++
124124
if monitor.statusOK && int(monitor.failedTimes) >= monitor.maxFailedTimes && monitor.statusFailedFn != nil {
125-
xl.Warn("health check status change to failed")
125+
xl.Warnf("health check status change to failed")
126126
monitor.statusOK = false
127127
monitor.statusFailedFn()
128128
}

client/proxy/proxy.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
141141
})
142142
}
143143

144-
xl.Trace("handle tcp work connection, useEncryption: %t, useCompression: %t",
144+
xl.Tracef("handle tcp work connection, useEncryption: %t, useCompression: %t",
145145
baseCfg.Transport.UseEncryption, baseCfg.Transport.UseCompression)
146146
if baseCfg.Transport.UseEncryption {
147147
remote, err = libio.WithEncryption(remote, encKey)
148148
if err != nil {
149149
workConn.Close()
150-
xl.Error("create encryption stream error: %v", err)
150+
xl.Errorf("create encryption stream error: %v", err)
151151
return
152152
}
153153
}
@@ -189,9 +189,9 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
189189

190190
if pxy.proxyPlugin != nil {
191191
// if plugin is set, let plugin handle connection first
192-
xl.Debug("handle by plugin: %s", pxy.proxyPlugin.Name())
192+
xl.Debugf("handle by plugin: %s", pxy.proxyPlugin.Name())
193193
pxy.proxyPlugin.Handle(remote, workConn, &extraInfo)
194-
xl.Debug("handle by plugin finished")
194+
xl.Debugf("handle by plugin finished")
195195
return
196196
}
197197

@@ -201,25 +201,25 @@ func (pxy *BaseProxy) HandleTCPWorkConnection(workConn net.Conn, m *msg.StartWor
201201
)
202202
if err != nil {
203203
workConn.Close()
204-
xl.Error("connect to local service [%s:%d] error: %v", baseCfg.LocalIP, baseCfg.LocalPort, err)
204+
xl.Errorf("connect to local service [%s:%d] error: %v", baseCfg.LocalIP, baseCfg.LocalPort, err)
205205
return
206206
}
207207

208-
xl.Debug("join connections, localConn(l[%s] r[%s]) workConn(l[%s] r[%s])", localConn.LocalAddr().String(),
208+
xl.Debugf("join connections, localConn(l[%s] r[%s]) workConn(l[%s] r[%s])", localConn.LocalAddr().String(),
209209
localConn.RemoteAddr().String(), workConn.LocalAddr().String(), workConn.RemoteAddr().String())
210210

211211
if extraInfo.ProxyProtocolHeader != nil {
212212
if _, err := extraInfo.ProxyProtocolHeader.WriteTo(localConn); err != nil {
213213
workConn.Close()
214-
xl.Error("write proxy protocol header to local conn error: %v", err)
214+
xl.Errorf("write proxy protocol header to local conn error: %v", err)
215215
return
216216
}
217217
}
218218

219219
_, _, errs := libio.Join(localConn, remote)
220-
xl.Debug("join connections closed")
220+
xl.Debugf("join connections closed")
221221
if len(errs) > 0 {
222-
xl.Trace("join connections errors: %v", errs)
222+
xl.Tracef("join connections errors: %v", errs)
223223
}
224224
if compressionResourceRecycleFn != nil {
225225
compressionResourceRecycleFn()

client/proxy/proxy_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (pm *Manager) UpdateAll(proxyCfgs []v1.ProxyConfigurer) {
152152
}
153153
}
154154
if len(delPxyNames) > 0 {
155-
xl.Info("proxy removed: %s", delPxyNames)
155+
xl.Infof("proxy removed: %s", delPxyNames)
156156
}
157157

158158
addPxyNames := make([]string, 0)
@@ -170,6 +170,6 @@ func (pm *Manager) UpdateAll(proxyCfgs []v1.ProxyConfigurer) {
170170
}
171171
}
172172
if len(addPxyNames) > 0 {
173-
xl.Info("proxy added: %s", addPxyNames)
173+
xl.Infof("proxy added: %s", addPxyNames)
174174
}
175175
}

0 commit comments

Comments
 (0)