Files
Marwan Sulaiman 5870aeee8d Remove Buffalo (#1010)
* Remove Buffalo

* gofmt

* pr fixes

* fix subrouter

* bring back secure middleware + pr fixes

* better place for subrouter

* vendor
2018-12-22 20:24:25 -05:00

26 lines
638 B
Go

package log
import (
"context"
)
type ctxKey string
const logEntryKey ctxKey = "log-entry-context-key"
// SetEntryInContext stores an Entry in the request context
func SetEntryInContext(ctx context.Context, e Entry) context.Context {
return context.WithValue(ctx, logEntryKey, e)
}
// EntryFromContext returns an Entry that has been stored in the request context.
// If there is no value for the key or the type assertion fails, it returns a new
// entry from the provided logger
func EntryFromContext(ctx context.Context) Entry {
e, ok := ctx.Value(logEntryKey).(Entry)
if !ok || e == nil {
return NoOpLogger()
}
return e
}