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 ¶ added in v6.7.0
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 ¶ added in v6.7.0
type RollupLogger interface { InfoD(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 ¶ added in v6.7.0
type RollupRouter struct {
// contains filtered or unexported fields
}
RollupRouter rolls up log lines and periodically logs them as one log line.
func NewRollupRouter ¶ added in v6.7.0
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 ¶ added in v6.7.0
func (r *RollupRouter) Process(logmsg map[string]interface{})
Process rolls up a log message.
func (*RollupRouter) ShouldRollup ¶ added in v6.7.0
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 200's and < 500ms.