Skip to content

Commit a7ff825

Browse files
committed
add klog and debug logging fix
1 parent 21e251c commit a7ff825

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

main.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ func NewProxyServer(configPath string, queueSize, workerCount int) *ProxyServer
144144
klog.V(2).Infof("Got SIGQUIT signal")
145145
// deliver rest of queue to FINAL destination
146146
default:
147-
klog.V(2).Infof("Some signal received: %v\n", sig)
147+
klog.V(2).Infof("Some signal received: %v", sig)
148148
}
149-
klog.V(1).Infof("Queue len is: %v\n", ps.getQueueLen())
149+
klog.V(1).Infof("Queue len is: %v", ps.getQueueLen())
150150
}
151151
}()
152152

@@ -162,12 +162,12 @@ func (p *ProxyServer) getQueueLen() int {
162162
func (p *ProxyServer) loadConfig() error {
163163
data, err := ioutil.ReadFile(p.configPath)
164164
if err != nil {
165-
klog.Fatal("Error reading config file: %v\n", err)
165+
klog.Fatal("Error reading config file: %v", err)
166166
}
167167

168168
var newConfig Config
169169
if err := yaml.Unmarshal(data, &newConfig); err != nil {
170-
klog.V(1).Infof("Error parsing config file: %v\n", err)
170+
klog.V(1).Infof("Error parsing config file: %v", err)
171171
return err
172172
}
173173

@@ -185,7 +185,7 @@ func (p *ProxyServer) loadConfig() error {
185185
}
186186
}
187187
if !found {
188-
klog.V(2).Infof("Deleting old host %v\n", key)
188+
klog.V(2).Infof("Deleting old host %v", key)
189189
p.config.Delete(key)
190190
}
191191
return true
@@ -214,7 +214,7 @@ func (p *ProxyServer) updateQueueLengthPeriodically() {
214214

215215
// worker processes requests from the queue
216216
func (p *ProxyServer) worker(id int) {
217-
klog.V(2).Infof("Worker %d started\n", id)
217+
klog.V(2).Infof("Worker %d started", id)
218218
for req := range p.queue {
219219
p.proxyRequest(req) // Process each request from the queue
220220
}
@@ -268,7 +268,7 @@ func (p *ProxyServer) proxyRequest(r *ForwardedRequest) {
268268

269269
if !found || len(backends) == 0 {
270270
p.totalFailed.WithLabelValues(host).Inc() // Increment failed request counter
271-
klog.V(1).Infof("Error host: '%v' not found in config file, droping request\n", host)
271+
klog.V(1).Infof("Error host: '%v' not found in config file, droping request", host)
272272
return
273273
}
274274

@@ -278,7 +278,7 @@ func (p *ProxyServer) proxyRequest(r *ForwardedRequest) {
278278
for i := 0; i <= backend.Retries; i++ {
279279
req, err := http.NewRequest(r.Req.Method, backend.Backend+r.Req.URL.Path, bytes.NewReader(r.Body));
280280
if err != nil {
281-
klog.V(4).Infof("Message failed for host %s with resp code %v error: %v\n", host, err)
281+
klog.V(4).Infof("Message failed for host %s with error: %v", backend.Backend, err)
282282
lastErr = err
283283
continue
284284
}
@@ -287,7 +287,7 @@ func (p *ProxyServer) proxyRequest(r *ForwardedRequest) {
287287
resp, err := client.Do(req)
288288
// Read the response body to ensure the connection can be reused
289289
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
290-
klog.V(1).Infof("Failed to read %v response body: %v\n", backend.Backend +r.Req.URL.Path, err)
290+
klog.V(1).Infof("Failed to read %v response body: %v", backend.Backend +r.Req.URL.Path, err)
291291
}
292292

293293
resp.Body.Close()
@@ -296,7 +296,7 @@ func (p *ProxyServer) proxyRequest(r *ForwardedRequest) {
296296
p.totalForwarded.WithLabelValues(host, backend.Backend).Inc()
297297
return
298298
} else {
299-
klog.V(4).Infof("Message failed for host %s with resp code %v error: %v\n", host,resp.StatusCode, err)
299+
klog.V(4).Infof("Message failed for host %s with resp code %v error: %v", backend.Backend, resp.StatusCode, err)
300300
}
301301
lastErr = err
302302
p.totalRetries.WithLabelValues(host, backend.Backend).Inc()
@@ -306,7 +306,7 @@ func (p *ProxyServer) proxyRequest(r *ForwardedRequest) {
306306

307307
// If we get here, all backends failed
308308
p.totalFailed.WithLabelValues(host).Inc()
309-
klog.V(1).Infof("All backends failed for host %s: %v\n", host, lastErr)
309+
klog.V(1).Infof("All backends failed for host %s: %v", host, lastErr)
310310
}
311311

312312
// handleIncomingRequest queues incoming requests
@@ -357,15 +357,15 @@ func main() {
357357
go func() {
358358
metricsMux := http.NewServeMux()
359359
metricsMux.Handle("/metrics", promhttp.Handler())
360-
klog.V(1).Infof("Prometheus metrics server listening on %s\n", conf.MetricsAddress)
360+
klog.V(1).Infof("Prometheus metrics server listening on %s", conf.MetricsAddress)
361361
err := http.ListenAndServe(conf.MetricsAddress, metricsMux)
362362
if err != nil {
363363
klog.Fatalf("Failed to start server: %v", err) // %v formats the error as a string
364364
}
365365
}()
366366

367367
// Start the proxy server
368-
klog.V(1).Infof("Proxy server is listening on %s\n", conf.ListenAddress)
368+
klog.V(1).Infof("Proxy server is listening on %s", conf.ListenAddress)
369369
err = http.ListenAndServe(conf.ListenAddress, nil)
370370
if err != nil {
371371
klog.Fatalf("Failed to start server: %v", err) // %v formats the error as a string

0 commit comments

Comments
 (0)