Example #1
0
File: log.go Project: nchern/go
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)
}
Example #2
0
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()))
}
Example #3
0
func DoLog(depth, logLvl int, msg string, lgr *log.Logger) {
	if lgr != nil {
		lgr.Output(depth, logPrefix+LogColor[logLvl]+msg+"\033[0m")
	}
}
Example #4
0
File: log.go Project: jamal/flannel
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...))
}
Example #5
0
func DoLog(depth int, msg string, lgr *log.Logger) {
	if lgr != nil {
		lgr.Output(depth, msg)
	}
}