MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Use

Method Use

pkg/log/logger.go:45–63  ·  view source on GitHub ↗

Use installs the handler middleware.

(middleware Middleware)

Source from the content-addressed store, hash-verified

43
44// Use installs the handler middleware.
45func (l *Logger) Use(middleware Middleware) {
46 l.mutex.Lock()
47 defer l.mutex.Unlock()
48
49 l.middleware = append(l.middleware, middleware)
50
51 // the first handler uses the base handler from the logger
52 // we need to wrap this is a function so the base handler can be
53 // changed afterwards.
54 handler := Handler(HandlerFunc(func(entry Entry) error {
55 return l.Handler.HandleLog(entry)
56 }))
57
58 for i := len(l.middleware) - 1; i >= 0; i-- {
59 handler = l.middleware[i].Wrap(handler)
60 }
61
62 l.stack = handler
63}
64
65// commit comits the entry to the handler.
66func (l *Logger) commit(e *entry) {

Callers 2

TestMiddlewareFunction · 0.95
ExampleMiddlewareFunction · 0.95

Calls 4

HandlerInterface · 0.70
HandlerFuncFuncType · 0.70
HandleLogMethod · 0.65
WrapMethod · 0.65

Tested by 2

TestMiddlewareFunction · 0.76
ExampleMiddlewareFunction · 0.76