mirror of
https://github.com/3bbbeau/tfvars-atlantis-config.git
synced 2025-12-05 22:01:43 +00:00
v0.0.1
This commit is contained in:
29
logger/logger.go
Normal file
29
logger/logger.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type loggerKey struct{}
|
||||
|
||||
// WithContext returns a new context with the logger added.
|
||||
func WithContext(ctx context.Context, l *zap.Logger) context.Context {
|
||||
return context.WithValue(ctx, loggerKey{}, l)
|
||||
}
|
||||
|
||||
// FromContext returns the logger in the context if it exists, otherwise a new
|
||||
// no-op logger is returned .
|
||||
func FromContext(ctx context.Context) *zap.Logger {
|
||||
if ctx == nil {
|
||||
return zap.NewNop()
|
||||
}
|
||||
|
||||
v := ctx.Value(loggerKey{})
|
||||
if v == nil {
|
||||
return zap.NewNop()
|
||||
}
|
||||
|
||||
return v.(*zap.Logger)
|
||||
}
|
||||
Reference in New Issue
Block a user