Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update breaking changes and refactoring so we're ready for logging
sinks.
  • Loading branch information
paddycarver committed Sep 21, 2021
1 parent 28f3599 commit c9c5ff7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/go-hclog v0.16.1
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/terraform-plugin-log v0.1.0
github.com/hashicorp/terraform-plugin-log v0.1.1-0.20210904065525-76e1d83026ab
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
github.com/vmihailenco/msgpack v4.0.4+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/terraform-plugin-log v0.1.0 h1:Y3WhhGY0ETvfHlCM0ad7BG1lzTNEblcmh6PrFw/4o9g=
github.com/hashicorp/terraform-plugin-log v0.1.0/go.mod h1:qRu7tRIL3c89jRYT7UBkSJ+DJ8NPPjQGawQgrGms47s=
github.com/hashicorp/terraform-plugin-log v0.1.1-0.20210904065525-76e1d83026ab h1:6YT7KEAKUtxpz4l3hlMdZ5Dr9eOI7bk1aDGxOA5tPcE=
github.com/hashicorp/terraform-plugin-log v0.1.1-0.20210904065525-76e1d83026ab/go.mod h1:M9/cBiG+lJx7KZqWlo2LfaqwsznLHKu7wgBIlEFpKn4=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 h1:1FGtlkJw87UsTMg5s8jrekrHmUPUJaMcu6ELiVhQrNw=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down
22 changes: 11 additions & 11 deletions tfprotov5/tf5server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-uuid"
tflog "github.com/hashicorp/terraform-plugin-log"
tfsdklog "github.com/hashicorp/terraform-plugin-log/sdk"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-log/tfsdklog"
tfaddr "github.com/hashicorp/terraform-registry-address"
)

Expand Down Expand Up @@ -156,8 +156,8 @@ type server struct {
stopMu sync.Mutex
stopCh chan struct{}

tflogSDKOpts []tfsdklog.Option
tflogOpts []tflog.Option
tflogSDKOpts tfsdklog.Options
tflogOpts tflog.Options
name string
}

Expand Down Expand Up @@ -194,19 +194,19 @@ func (s *server) loggingContext(ctx context.Context) context.Context {
}

// set up the logger SDK loggers are derived from
ctx = tfsdklog.New(ctx, append([]tfsdklog.Option{
ctx = tfsdklog.NewRootSDKLogger(ctx, append(tfsdklog.Options{
tfsdklog.WithLevelFromEnv("TF", "LOG", "SDK"),
}, s.tflogSDKOpts...)...)
ctx = tfsdklog.With(ctx, "tf_req_id", reqID)
ctx = tfsdklog.With(ctx, "tf_provider_addr", s.name)

// set up our protocol-level subsystem logger
ctx = tfsdklog.NewSubsystem(ctx, tflogSubsystemName, append([]tfsdklog.Option{
ctx = tfsdklog.NewSubsystem(ctx, tflogSubsystemName, append(tfsdklog.Options{
tfsdklog.WithLevelFromEnv("TF", "LOG", "SDK", "PROTO"),
}, s.tflogSDKOpts...)...)

// set up the provider logger
ctx = tflog.New(ctx, s.tflogOpts...)
ctx = tfsdklog.NewRootProviderLogger(ctx, s.tflogOpts...)
ctx = tflog.With(ctx, "tf_req_id", reqID)
ctx = tflog.With(ctx, "tf_provider_addr", s.name)
return ctx
Expand Down Expand Up @@ -245,12 +245,12 @@ func New(name string, serve tfprotov5.ProviderServer, opts ...ServeOpt) tfplugin
panic(err)
}
}
var sdkOptions []tfsdklog.Option
var options []tflog.Option
var sdkOptions tfsdklog.Options
var options tflog.Options
sdkOptions = append(sdkOptions, tfsdklog.WithLevelFromEnv("TF", "LOG", "SDK", "PROTO"))
if !conf.disableLogInitStderr {
sdkOptions = append(sdkOptions, tfsdklog.WithStderrFromInit())
options = append(options, tflog.WithStderrFromInit())
options = append(options, tfsdklog.WithStderrFromInit())
}
if conf.disableLogLocation {
sdkOptions = append(sdkOptions, tfsdklog.WithoutLocation())
Expand All @@ -267,7 +267,7 @@ func New(name string, serve tfprotov5.ProviderServer, opts ...ServeOpt) tfplugin
}
envVar = strings.ReplaceAll(envVar, "-", "_")
if envVar != "" {
options = append(options, tflog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
options = append(options, tfsdklog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
}
return &server{
downstream: serve,
Expand Down
22 changes: 11 additions & 11 deletions tfprotov6/tf6server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-uuid"
tflog "github.com/hashicorp/terraform-plugin-log"
tfsdklog "github.com/hashicorp/terraform-plugin-log/sdk"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-log/tfsdklog"
tfaddr "github.com/hashicorp/terraform-registry-address"
)

Expand Down Expand Up @@ -158,8 +158,8 @@ type server struct {
stopMu sync.Mutex
stopCh chan struct{}

tflogSDKOpts []tfsdklog.Option
tflogOpts []tflog.Option
tflogSDKOpts tfsdklog.Options
tflogOpts tflog.Options
name string
}

Expand Down Expand Up @@ -196,19 +196,19 @@ func (s *server) loggingContext(ctx context.Context) context.Context {
}

// set up the logger SDK loggers are derived from
ctx = tfsdklog.New(ctx, append([]tfsdklog.Option{
ctx = tfsdklog.NewRootSDKLogger(ctx, append(tfsdklog.Options{
tfsdklog.WithLevelFromEnv("TF", "LOG", "SDK"),
}, s.tflogSDKOpts...)...)
ctx = tfsdklog.With(ctx, "tf_req_id", reqID)
ctx = tfsdklog.With(ctx, "tf_provider_addr", s.name)

// set up our protocol-level subsystem logger
ctx = tfsdklog.NewSubsystem(ctx, tflogSubsystemName, append([]tfsdklog.Option{
ctx = tfsdklog.NewSubsystem(ctx, tflogSubsystemName, append(tfsdklog.Options{
tfsdklog.WithLevelFromEnv("TF", "LOG", "SDK", "PROTO"),
}, s.tflogSDKOpts...)...)

// set up the provider logger
ctx = tflog.New(ctx, s.tflogOpts...)
ctx = tfsdklog.NewRootProviderLogger(ctx, s.tflogOpts...)
ctx = tflog.With(ctx, "tf_req_id", reqID)
ctx = tflog.With(ctx, "tf_provider_addr", s.name)
return ctx
Expand Down Expand Up @@ -247,11 +247,11 @@ func New(name string, serve tfprotov6.ProviderServer, opts ...ServeOpt) tfplugin
panic(err)
}
}
var sdkOptions []tfsdklog.Option
var options []tflog.Option
var sdkOptions tfsdklog.Options
var options tflog.Options
if !conf.disableLogInitStderr {
sdkOptions = append(sdkOptions, tfsdklog.WithStderrFromInit())
options = append(options, tflog.WithStderrFromInit())
options = append(options, tfsdklog.WithStderrFromInit())
}
if conf.disableLogLocation {
sdkOptions = append(sdkOptions, tfsdklog.WithoutLocation())
Expand All @@ -268,7 +268,7 @@ func New(name string, serve tfprotov6.ProviderServer, opts ...ServeOpt) tfplugin
}
envVar = strings.ReplaceAll(envVar, "-", "_")
if envVar != "" {
options = append(options, tflog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
options = append(options, tfsdklog.WithLogName(envVar), tflog.WithLevelFromEnv("TF", "LOG", "PROVIDER", envVar))
}
return &server{
downstream: serve,
Expand Down

0 comments on commit c9c5ff7

Please sign in to comment.