英文:
Idea Intellij how to navigate to line from console's print statement
问题
在我通过Idea IntelliJ 2016.3运行的golang项目中,有各种fmt.Println语句。有没有办法从控制台的打印语句中导航到代码?我想知道是哪段代码打印了控制台上的那一行。
英文:
There are various fmt.Println statements in my golang project which I run through Idea IntelliJ version 2016.3. Is there any way I navigate to the code from console's printed statements? I want know what code is printing the line [rinted on console.
答案1
得分: 3
我建议你查看日志包。
https://golang.org/pkg/log/
package main
import (
"log"
)
func main() {
log.SetFlags(log.Lshortfile)
log.Println("Hello world") // main.go:9: Hello world
}
https://play.golang.org/p/lQGW6P10fs
英文:
I'd recommend looking into the log package.
https://golang.org/pkg/log/
package main
import (
"log"
)
func main() {
log.SetFlags(log.Lshortfile)
log.Println("Hello world") // main.go:9: Hello world
}
答案2
得分: 0
我知道现在已经很晚了,但也许可以帮助其他人。
你可以使用function, file, line, ok := runtime.Caller(1)
来获取运行时的位置,例如,你可以使用这个项目来处理你的错误。
英文:
I know it's late but maybe help others
you can use function, file, line, ok := runtime.Caller(1)
to get where is the runtime, for example, you can use this project for your error
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论