ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# 调试模块 我们经常需要打印一些参数进行调试,但是默认的参数打印总是不是很完美,也没办法定位代码行之类的,所以 beego 的 toolbox 模块进行了 debug 模块的开发,主要包括了两个函数: * Display() 直接打印结果到 console * GetDisplayString() 返回打印的字符串 两个函数的功能一模一样,第一个是直接打印到 console,第二个是返回字符串,方便用户存储到日志或者其他存储。 使用很方便,是 key/value 串出现的,如下示例: ~~~ Display("v1", 1, "v2", 2, "v3", 3) ~~~ 打印结果如下: ~~~ 2013/12/16 23:48:41 [Debug] at TestPrint() [/Users/astaxie/github/beego/toolbox/debug_test.go:13] [Variables] v1 = 1 v2 = 2 v3 = 3 ~~~ 指针类型的打印如下: ~~~ type mytype struct { next *mytype prev *mytype } var v1 = new(mytype) var v2 = new(mytype) v1.prev = nil v1.next = v2 v2.prev = v1 v2.next = nil Display("v1", v1, "v2", v2) ~~~ 打印结果如下: ~~~ 2013/12/16 23:48:41 [Debug] at TestPrintPoint() [/Users/astaxie/github/beego/toolbox/debug_test.go:26] [Variables] v1 = &toolbox.mytype{ next: &toolbox.mytype{ next: nil, prev: 0x210335420, }, prev: nil, } v2 = &toolbox.mytype{ next: nil, prev: &toolbox.mytype{ next: 0x210335430, prev: nil, }, } ~~~