dongqian0763
dongqian0763
2016-12-13 06:11

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

已采纳

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douzhe2981 douzhe2981 5年前

    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

    点赞 评论 复制链接分享
  • douchu4048 douchu4048 3年前

    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

    点赞 评论 复制链接分享