2020-03-27 12:35:57 +01:00
|
|
|
package zfscmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-04-11 15:49:41 +02:00
|
|
|
"github.com/zrepl/zrepl/daemon/logging"
|
2020-03-27 12:35:57 +01:00
|
|
|
"github.com/zrepl/zrepl/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKey int
|
|
|
|
|
|
|
|
const (
|
2020-04-11 15:49:41 +02:00
|
|
|
contextKeyJobID contextKey = 1 + iota
|
2020-03-27 12:35:57 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Logger = logger.Logger
|
|
|
|
|
|
|
|
func WithJobID(ctx context.Context, jobID string) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyJobID, jobID)
|
|
|
|
}
|
|
|
|
|
2023-05-02 22:13:52 +02:00
|
|
|
func GetJobIDOrDefault(ctx context.Context, def string) string {
|
|
|
|
return getJobIDOrDefault(ctx, def)
|
|
|
|
}
|
|
|
|
|
2020-03-27 12:35:57 +01:00
|
|
|
func getJobIDOrDefault(ctx context.Context, def string) string {
|
|
|
|
ret, ok := ctx.Value(contextKeyJobID).(string)
|
|
|
|
if !ok {
|
|
|
|
return def
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLogger(ctx context.Context) Logger {
|
2020-04-11 15:49:41 +02:00
|
|
|
return logging.GetLogger(ctx, logging.SubsysZFSCmd)
|
2020-03-27 12:35:57 +01:00
|
|
|
}
|