reduce calls to Debugf when not debugging to reduce slice allocs

ref #129
This commit is contained in:
Lucas Clemente
2016-06-04 15:13:46 +02:00
parent 0f941214b4
commit 6a46465092
5 changed files with 84 additions and 17 deletions

19
frames/log.go Normal file
View File

@@ -0,0 +1,19 @@
package frames
import "github.com/lucas-clemente/quic-go/utils"
// LogFrame logs a frame, either sent or received
func LogFrame(frame Frame, sent bool) {
if !utils.Debug() {
return
}
dir := "<-"
if sent {
dir = "->"
}
if sf, ok := frame.(*StreamFrame); ok {
utils.Debugf("\t%s &frames.StreamFrame{StreamID: %d, FinBit: %t, Offset: 0x%x, Data length: 0x%x, Offset + Data length: 0x%x}", dir, sf.StreamID, sf.FinBit, sf.Offset, sf.DataLen(), sf.Offset+sf.DataLen())
} else {
utils.Debugf("\t%s %#v", dir, frame)
}
}