package logbuffer

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

func UseLogBuffer(queue *Queue) gin.HandlerFunc {
	return gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
		output := fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
			param.ClientIP,
			param.TimeStamp.Format(time.RFC1123),
			param.Method,
			param.Path,
			param.Request.Proto,
			param.StatusCode,
			param.Latency,
			param.Request.UserAgent(),
			param.ErrorMessage,
		)

		// Write the output to our queue
		queue.push(output)
		queue.Limit(200)

		// Return nothing
		return ""
	})
}



