0

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.

codec
  • 7,978
  • 26
  • 71
  • 127
  • fmt.Println prints bytes to a the stdout descriptor, so the only way to refer back to the file would be to print the file and line number in addition to the other text. You can [find these by examining the call stack](https://stackoverflow.com/questions/35212985/is-it-possible-get-information-about-caller-function-in-golang) and add the to the message in a format that idea understands. – nothingmuch Dec 13 '16 at 06:53

2 Answers2

3

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

Omar
  • 1,329
  • 11
  • 9
0

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

sadeghpro
  • 448
  • 2
  • 8
  • 24