Documentation ¶
Overview ¶
Package middleware provides a customizable Kayvee logging middleware for HTTP servers.
logHandler := New(myHandler, myLogger, func(req *http.Request) map[string]interface{} { // Add Gorilla mux vars to the log, just because return mux.Vars(req) })
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnableRollups ¶
func EnableRollups(ctx context.Context, logger RollupLogger, reportingInterval time.Duration)
EnableRollups turns on rollups for kv middleware logs.
func HeaderHandler ¶
HeaderHandler takes in any amount of headers and returns a handler that adds those headers.
func New ¶
func New(h http.Handler, source string, handlers ...func(*http.Request) map[string]interface{}) http.Handler
New takes in an http Handler to wrap with logging, the logger source name to use, and any amount of optional handlers to customize the data that's logged. On every request, the middleware will create a logger and place it in req.Context().
Types ¶
type RollupLogger ¶
type RollupLogger interface { InfoD(title string, data map[string]interface{}) WarnD(title string, data map[string]interface{}) ErrorD(title string, data map[string]interface{}) }
RollupLogger will log info / error rollups depending on status code.
type RollupRouter ¶
type RollupRouter struct {
// contains filtered or unexported fields
}
RollupRouter rolls up log lines and periodically logs them as one log line.
func NewRollupRouter ¶
func NewRollupRouter(ctx context.Context, logger RollupLogger, reportingDelay time.Duration) *RollupRouter
NewRollupRouter creates a new log rollup output. Rollups will stop when the context is canceled.
func (*RollupRouter) Process ¶
func (r *RollupRouter) Process(logmsg map[string]interface{})
Process rolls up a log message.
func (*RollupRouter) ShouldRollup ¶
func (r *RollupRouter) ShouldRollup(logmsg map[string]interface{}) bool
ShouldRollup returns true when a log msg meets the criteria for rollup. In the future allow more configurability, for now default to 2xx's and < 500ms.