logger.go
func Logger() Handler {
	return func(ctx *Context, log *log.Logger) {
		start := time.Now()

		log.Printf("%s: Started %s %s for %s", time.Now().Format(LogTimeFormat), ctx.Req.Method, ctx.Req.RequestURI, ctx.RemoteAddr())

		rw := ctx.Resp.(ResponseWriter)
		ctx.Next()

		content := fmt.Sprintf("%s: Completed %s %s %v %s in %v", time.Now().Format(LogTimeFormat), ctx.Req.Method, ctx.Req.RequestURI, rw.Status(), http.StatusText(rw.Status()), time.Since(start))
		if ColorLog {
			switch rw.Status() {
			case 200, 201, 202:
				content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
			case 301, 302:
				content = fmt.Sprintf("\033[1;37m%s\033[0m", content)
			case 304:
				content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
			case 401, 403:
				content = fmt.Sprintf("\033[4;31m%s\033[0m", content)
			case 404:
				content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
			case 500:
				content = fmt.Sprintf("\033[1;36m%s\033[0m", content)
			}
		}
		log.Println(content)
	}
}
func Logger() Handler {
	return func(ctx *Context, log *log.Logger) {
		start := time.Now()

		log.Printf("%s: Started %s %s for %s", time.Now().Format(LogTimeFormat), ctx.Req.Method, ctx.Req.RequestURI, ctx.RemoteAddr())

		rw := ctx.Resp.(ResponseWriter)
		ctx.Next()

		content := fmt.Sprintf("%s: Completed %s %s %v %s in %v", time.Now().Format(LogTimeFormat), ctx.Req.Method, ctx.Req.RequestURI, rw.Status(), http.StatusText(rw.Status()), time.Since(start))
		if ColorLog {
			switch rw.Status() {
			case 200, 201, 202:
				content = fmt.Sprintf("\033[1;32m%s\033[0m", content)
			case 301, 302:
				content = fmt.Sprintf("\033[1;37m%s\033[0m", content)
			case 304:
				content = fmt.Sprintf("\033[1;33m%s\033[0m", content)
			case 401, 403:
				content = fmt.Sprintf("\033[4;31m%s\033[0m", content)
			case 404:
				content = fmt.Sprintf("\033[1;31m%s\033[0m", content)
			case 500:
				content = fmt.Sprintf("\033[1;36m%s\033[0m", content)
			}
		}
		log.Println(content)
	}
}
func Logger ( ) Handler { return func ( ctx * Context , log * log . Logger ) { start := time . Now ( ) log . Printf ( " " , time . Now ( ) . Format ( LogTimeFormat ) , ctx . Req . Method , ctx . Req . RequestURI , ctx . RemoteAddr ( ) ) rw := ctx . Resp . ( ResponseWriter ) ctx . Next ( ) content := fmt . Sprintf ( " " , time . Now ( ) . Format ( LogTimeFormat ) , ctx . Req . Method , ctx . Req . RequestURI , rw . Status ( ) , http . StatusText ( rw . Status ( ) ) , time . Since ( start ) ) if ColorLog { switch rw . Status ( ) { case 200 , 201 , 202 : content = fmt . Sprintf ( " \033 \033 " , content ) case 301 , 302 : content = fmt . Sprintf ( " \033 \033 " , content ) case 304 : content = fmt . Sprintf ( " \033 \033 " , content ) case 401 , 403 : content = fmt . Sprintf ( " \033 \033 " , content ) case 404 : content = fmt . Sprintf ( " \033 \033 " , content ) case 500 : content = fmt . Sprintf ( " \033 \033 " , content ) } } log . Println ( content ) } }
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
Logger returns a middleware handler that logs the request as it goes in and the response as it goes out .