84c9110a24
Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.24.1 to 2.26.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.24.1...v2.26.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package logging
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
)
|
|
|
|
// GetSink returns the sink logger used for writing logs.
|
|
// If no sink logger has been created, it will return nil.
|
|
func GetSink(ctx context.Context) hclog.Logger {
|
|
logger := ctx.Value(SinkKey)
|
|
if logger == nil {
|
|
return nil
|
|
}
|
|
|
|
hclogger, ok := logger.(hclog.Logger)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
return hclogger
|
|
}
|
|
|
|
// GetSinkOptions returns the root logger options used for
|
|
// creating the root SDK logger. If the root logger has not been created or
|
|
// the options are not present, it will return nil.
|
|
func GetSinkOptions(ctx context.Context) *hclog.LoggerOptions {
|
|
if GetSink(ctx) == nil {
|
|
return nil
|
|
}
|
|
|
|
loggerOptionsRaw := ctx.Value(SinkOptionsKey)
|
|
|
|
if loggerOptionsRaw == nil {
|
|
return nil
|
|
}
|
|
|
|
loggerOptions, ok := loggerOptionsRaw.(*hclog.LoggerOptions)
|
|
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
return loggerOptions
|
|
}
|
|
|
|
// SetSink sets `logger` as the sink logger used for writing logs.
|
|
func SetSink(ctx context.Context, logger hclog.Logger) context.Context {
|
|
return context.WithValue(ctx, SinkKey, logger)
|
|
}
|
|
|
|
// SetSinkOptions sets `loggerOptions` as the root logger options
|
|
// used for creating the SDK root logger.
|
|
func SetSinkOptions(ctx context.Context, loggerOptions *hclog.LoggerOptions) context.Context {
|
|
return context.WithValue(ctx, SinkOptionsKey, loggerOptions)
|
|
}
|