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) }
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())) }
func DoLog(depth, logLvl int, msg string, lgr *log.Logger) { if lgr != nil { lgr.Output(depth, logPrefix+LogColor[logLvl]+msg+"\033[0m") } }
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...)) }
func DoLog(depth int, msg string, lgr *log.Logger) { if lgr != nil { lgr.Output(depth, msg) } }