mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 08:45:38 +00:00
25 lines
417 B
Go
25 lines
417 B
Go
package logging
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
type contextKey int
|
|
|
|
const (
|
|
contextKeyLogWriter contextKey = iota
|
|
)
|
|
|
|
func WriterFromContext(ctx context.Context) io.Writer {
|
|
writer, ok := ctx.Value(contextKeyLogWriter).(io.Writer)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return writer
|
|
}
|
|
|
|
func ContextWithWriter(ctx context.Context, logger io.Writer) context.Context {
|
|
return context.WithValue(ctx, contextKeyLogWriter, logger)
|
|
}
|