2018-08-22 00:43:58 +02:00
|
|
|
package endpoint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-03-22 19:41:12 +01:00
|
|
|
|
2018-08-22 00:43:58 +02:00
|
|
|
"github.com/zrepl/zrepl/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKey int
|
|
|
|
|
|
|
|
const (
|
|
|
|
contextKeyLogger contextKey = iota
|
2018-12-11 22:01:50 +01:00
|
|
|
ClientIdentityKey
|
2018-08-22 00:43:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Logger = logger.Logger
|
|
|
|
|
|
|
|
func WithLogger(ctx context.Context, log Logger) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyLogger, log)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLogger(ctx context.Context) Logger {
|
2018-08-31 16:26:11 +02:00
|
|
|
if l, ok := ctx.Value(contextKeyLogger).(Logger); ok {
|
|
|
|
return l
|
2018-08-22 00:43:58 +02:00
|
|
|
}
|
2018-08-31 16:26:11 +02:00
|
|
|
return logger.NewNullLogger()
|
2018-08-22 00:43:58 +02:00
|
|
|
}
|