Getting line number

896 views
Skip to first unread message

Starfish

unread,
Mar 8, 2013, 5:23:53 AM3/8/13
to golan...@googlegroups.com
I often use debug printouts to find errors. Often however, I confuse what is printing what.

Question: Is there an easy way to print the line number of the current source file.

minux

unread,
Mar 8, 2013, 6:25:59 AM3/8/13
to Starfish, golan...@googlegroups.com

On Friday, March 8, 2013, Starfish wrote: 
I often use debug printouts to find errors. Often however, I confuse what is printing what.
Question: Is there an easy way to print the line number of the current source file.
runtime.Caller

Thomas Kappler

unread,
Mar 8, 2013, 7:11:52 AM3/8/13
to golan...@googlegroups.com
On Friday, March 8, 2013 11:23:53 AM UTC+1, Starfish wrote:
I often use debug printouts to find errors. Often however, I confuse what is printing what.

Question: Is there an easy way to print the line number of the current source file.

You can print your debug statements using the "log" package and set the log.Lshortfile flag, for example like that:

log.SetFlags(log.Lshortfile | log.Ldate | log.Ltime)

Starfish

unread,
Mar 8, 2013, 8:33:13 AM3/8/13
to golan...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages