Files
athens/pkg/log/log_context.go
Nicholas Wiersma d932d50232 chore: lint code with golangci-lint (#1828)
* feat: add golangci-lint linting

* chore: fix linter issues

* feat: add linting into the workflow

* docs: update lint docs

* fix: cr suggestions

* fix: remove old formatting and vetting scripts

* fix: add docker make target

* fix: action go caching

* fix: depreciated actions checkout version

* fix: cr suggestion

* fix: cr suggestions

---------

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
2023-02-24 20:39:17 -08:00

26 lines
640 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
}