github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/common/utils/debug/debug.go (about) 1 package debug 2 3 import ( 4 "github.com/nyan233/littlerpc/core/common/logger" 5 "github.com/nyan233/littlerpc/core/protocol/message/analysis" 6 "github.com/nyan233/littlerpc/internal/pool" 7 "runtime" 8 ) 9 10 type Func func(logger logger.LLogger, open bool) func(bytes []byte, useMux bool) 11 12 type RawFunc func(logger logger.LLogger, open bool) func(message interface{}, useMux bool) 13 14 // ServerRecover TODO: 将该函数的实现移动到internal/pool中 15 func ServerRecover(logger logger.LLogger) pool.RecoverFunc { 16 return func(poolId int, err interface{}) { 17 var buf [4096]byte 18 length := runtime.Stack(buf[:], false) 19 logger.Error("LRPC: poolId : %d -> Panic : %v\n%s", poolId, err, string(buf[:length])) 20 } 21 } 22 23 func MessageDebug(logger logger.LLogger, open bool) func(bytes []byte, useMux bool) { 24 return func(bytes []byte, useMux bool) { 25 switch { 26 case open && useMux: 27 logger.Debug(analysis.Mux(bytes).String()) 28 case open && !useMux: 29 logger.Debug(analysis.NoMux(bytes).String()) 30 } 31 } 32 }