本文整理汇总了Golang中log.Logger.Output方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Output方法的具体用法?Golang Logger.Output怎么用?Golang Logger.Output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log.Logger
的用法示例。
在下文中一共展示了Logger.Output方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: logIt
func logIt(l *log.Logger, level, format string, v ...interface{}) {
msg := ""
if format != "" {
msg = fmt.Sprintf(format, v...)
} else {
msg = fmt.Sprint(v...)
}
l.Output(3, level+" "+msg)
}
示例2: HTTPServer
func HTTPServer(listener net.Listener, handler http.Handler, l *log.Logger, proto string) {
l.Output(2, fmt.Sprintf("%s: listening on %s", proto, listener.Addr()))
server := &http.Server{
Handler: handler,
}
err := server.Serve(listener)
// theres no direct way to detect this error because it is not exposed
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
l.Output(2, fmt.Sprintf("ERROR: http.Serve() - %s", err))
}
l.Output(2, fmt.Sprintf("%s: closing %s", proto, listener.Addr()))
}
示例3: DoLog
func DoLog(depth, logLvl int, msg string, lgr *log.Logger) {
if lgr != nil {
lgr.Output(depth, logPrefix+LogColor[logLvl]+msg+"\033[0m")
}
}
示例4: logOut
func logOut(logger *log.Logger, level string, r *http.Request, format string, v ...interface{}) {
logger.SetPrefix(fmt.Sprintf("[%6s] %s ", level, reqID(r)))
logger.Output(3, fmt.Sprintf(format, v...))
}
示例5: DoLog
func DoLog(depth int, msg string, lgr *log.Logger) {
if lgr != nil {
lgr.Output(depth, msg)
}
}