Idea Intellij如何从控制台的打印语句导航到相应的行?

huangapple go评论93阅读模式
英文:

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
}

https://play.golang.org/p/lQGW6P10fs

答案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

huangapple
  • 本文由 发表于 2016年12月13日 14:11:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/41114683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定