log.Print() ? log.Println() ? What the difference ?

2,826 views
Skip to first unread message

Guillaume Lescure

unread,
Sep 14, 2012, 6:38:46 PM9/14/12
to golan...@googlegroups.com
Hi,

It's maybe a bug but when I write log.Print(), it's make a "\n" at the end so it's exactly like log.Println() isn't it ?
Did I miss something ?

Regards

Mike Rosset

unread,
Sep 14, 2012, 6:49:07 PM9/14/12
to Guillaume Lescure, golan...@googlegroups.com
> --
>
>

This is not a bug. And when you really think about it quite logical.

Patrick Mylund Nielsen

unread,
Sep 14, 2012, 6:50:37 PM9/14/12
to Mike Rosset, Guillaume Lescure, golan...@googlegroups.com
You could say it's a bug that the Print method exists in the first place.


--



Andrew Gerrand

unread,
Sep 14, 2012, 7:00:30 PM9/14/12
to Guillaume Lescure, golan...@googlegroups.com
They have different behaviors.

func Print(a ...interface{}) (n int, err error)
Print formats using the default formats for its operands and writes to
standard output. Spaces are added between operands when neither is a
string. It returns the number of bytes written and any write error
encountered.

func Println(a ...interface{}) (n int, err error)
Println formats using the default formats for its operands and writes to
standard output. Spaces are always added between operands and a newline
is appended. It returns the number of bytes written and any write error
encountered.

For example: http://play.golang.org/p/yia7SUt6Rv

Andrew

Guillaume Lescure

unread,
Sep 14, 2012, 7:05:43 PM9/14/12
to golan...@googlegroups.com, Guillaume Lescure
Thank you, that what I didn't understand the first time. Now I see the difference :)

Regards,

fritz

unread,
May 4, 2013, 12:37:43 AM5/4/13
to golan...@googlegroups.com, Guillaume Lescure
That seems misleading as the convention in fmt is that Print also differs from Println by a newline, and the documentation for log reads as if they share the behavior from fmt.
Reply all
Reply to author
Forward
0 new messages