Skip to content

Commit b7a1f18

Browse files
Small fixes related to debug logging
1 parent 272ab32 commit b7a1f18

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

gohpts.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ func (app *app) handleForward(w http.ResponseWriter, r *http.Request) {
122122
}
123123
var written string
124124
if n < 1000 {
125-
written = fmt.Sprintf("%d Bytes", n)
125+
written = fmt.Sprintf("%dB", n)
126126
} else {
127-
written = fmt.Sprintf("%d KB", n)
127+
written = fmt.Sprintf("%dKB", n/1000)
128128
}
129129
app.logger.Debug().Msgf("%s - %s - %s - %d - %s", r.Proto, r.Method, r.Host, resp.StatusCode, written)
130130
}
@@ -175,11 +175,17 @@ func (app *app) handleTunnel(w http.ResponseWriter, r *http.Request) {
175175

176176
func (app *app) transfer(wg *sync.WaitGroup, destination io.Writer, source io.Reader, destName, srcName string) {
177177
defer wg.Done()
178-
written, err := io.Copy(destination, source)
178+
n, err := io.Copy(destination, source)
179179
if err != nil {
180180
app.logger.Error().Err(err).Msgf("Error during copy from %s to %s: %v", srcName, destName, err)
181181
}
182-
app.logger.Debug().Msgf("copied %d bytes from %s to %s", written, srcName, destName)
182+
var written string
183+
if n < 1000 {
184+
written = fmt.Sprintf("%dB", n)
185+
} else {
186+
written = fmt.Sprintf("%dKB", n/1000)
187+
}
188+
app.logger.Debug().Msgf("copied %s from %s to %s", written, srcName, destName)
183189
}
184190

185191
func (app *app) handler() http.HandlerFunc {

0 commit comments

Comments
 (0)