为什么我应该使用log.Println而不是fmt.Println? [英] Why should I use log.Println instead of fmt.Println?
问题描述
从 log.go (执行日志包):
167 // Println调用l.Output打印到记录器。
168 //参数以fmt.Println的方式处理。
169 func(l * Logger)Println(v ... interface {}){l.Output(2,fmt.Sprintln(v ...))}
任何实际的原因? 有两种情况是不同的: goroutines( Log可以自动添加计时信息。 所以这些是两个完全不同的东西。日志记录用于格式化, From log.go (the implementation of the log package) : Any practical reasons ? Two things are different: Printing via package log is safe from concurrent goroutines (which plain Log can add timing information automatically. So these are two complete different things. log is for logging and 这篇关于为什么我应该使用log.Println而不是fmt.Println?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! log.Println
只是一个用于 fmt.Sprintln
,为什么我应该使用它而不是 fmt.Println
或 <$ c
fmt
不是)
fmt
用于格式化。 (好吧,日志使用相同的动词和标志,但这很方便)。167 // Println calls l.Output to print to the logger.
168 // Arguments are handled in the manner of fmt.Println.
169 func (l *Logger) Println(v ...interface{}) { l.Output(2, fmt.Sprintln(v...)) }
log.Println
is just a function wrapper for fmt.Sprintln
, why should I use it instead of fmt.Println
or fmt.Sprintln
?
fmt
isn't)fmt
for formatting. (Okay, log uses the same verbs and flags, but that is just convenient).