diff --git a/.changelog/78.txt b/.changelog/78.txt new file mode 100644 index 0000000..467209f --- /dev/null +++ b/.changelog/78.txt @@ -0,0 +1,111 @@ +```release-note:breaking-change +tflog: renamed `With()` to `SetField()` +``` + +```release-note:breaking-change +tflog: renamed `WithOmitLogWithFieldKeys()` to `OmitLogWithFieldKeys()` +``` + +```release-note:breaking-change +tflog: renamed `WithOmitLogWithMessageRegex()` to `OmitLogWithMessageRegexes()` +``` + +```release-note:breaking-change +tflog: renamed `WithOmitLogMatchingString()` to `OmitLogWithMessageStrings()` +``` + +```release-note:breaking-change +tflog: renamed `WithMaskFieldValueWithFieldKeys()` to `MaskFieldValuesWithFieldKeys()` +``` + +```release-note:breaking-change +tflog: renamed `WithMaskMessageRegex()` to `MaskMessageRegexes()` +``` + +```release-note:breaking-change +tflog: renamed `WithMaskLogMatchingString()` to `MaskMessageStrings()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWith()` to `SubsystemSetField()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithOmitLogWithFieldKeys()` to `SubsystemOmitLogWithFieldKeys()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithOmitLogWithMessageRegex()` to `SubsystemOmitLogWithMessageRegexes()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithOmitLogMatchingString()` to `SubsystemOmitLogWithMessageStrings()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithMaskFieldValueWithFieldKeys()` to `SubsystemMaskFieldValuesWithFieldKeys()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithMaskMessageRegex()` to `SubsystemMaskMessageRegexes()` +``` + +```release-note:breaking-change +tflog: renamed `SubsystemWithMaskLogMatchingString()` to `SubsystemMaskMessageStrings()` +``` + +```release-note:breaking-change +tfsdklog: renamed `With()` to `SetField()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithOmitLogWithFieldKeys()` to `OmitLogWithFieldKeys()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithOmitLogWithMessageRegex()` to `OmitLogWithMessageRegexes()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithOmitLogMatchingString()` to `OmitLogWithMessageStrings()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithMaskFieldValueWithFieldKeys()` to `MaskFieldValuesWithFieldKeys()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithMaskMessageRegex()` to `MaskMessageRegexes()` +``` + +```release-note:breaking-change +tfsdklog: renamed `WithMaskLogMatchingString()` to `MaskMessageStrings()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWith()` to `SubsystemSetField()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithOmitLogWithFieldKeys()` to `SubsystemOmitLogWithFieldKeys()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithOmitLogWithMessageRegex()` to `SubsystemOmitLogWithMessageRegexes()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithOmitLogMatchingString()` to `SubsystemOmitLogWithMessageStrings()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithMaskFieldValueWithFieldKeys()` to `SubsystemMaskFieldValuesWithFieldKeys()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithMaskMessageRegex()` to `SubsystemMaskMessageRegexes()` +``` + +```release-note:breaking-change +tfsdklog: renamed `SubsystemWithMaskLogMatchingString()` to `SubsystemMaskMessageStrings()` +``` diff --git a/internal/logging/filtering.go b/internal/logging/filtering.go index 0834911..efc4f94 100644 --- a/internal/logging/filtering.go +++ b/internal/logging/filtering.go @@ -12,12 +12,12 @@ const logMaskingReplacementString = "***" // ShouldOmit takes a log's *string message and slices of arguments, // and determines, based on the LoggerOpts configuration, if the // log should be omitted (i.e. prevent it to be printed on the final writer). -func (lo LoggerOpts) ShouldOmit(msg *string, argSlices ...[]interface{}) bool { +func (lo LoggerOpts) ShouldOmit(msg *string, hclogArgSlices ...[]interface{}) bool { // Omit log if any of the configured keys is found // either in the logger implied arguments, // or in the additional arguments if len(lo.OmitLogWithFieldKeys) > 0 { - for _, args := range argSlices { + for _, args := range hclogArgSlices { argKeys := hclogutils.ArgsToKeys(args) if argKeysContain(argKeys, lo.OmitLogWithFieldKeys) { return true @@ -26,8 +26,8 @@ func (lo LoggerOpts) ShouldOmit(msg *string, argSlices ...[]interface{}) bool { } // Omit log if any of the configured regexp matches the log message - if len(lo.OmitLogWithMessageRegex) > 0 { - for _, r := range lo.OmitLogWithMessageRegex { + if len(lo.OmitLogWithMessageRegexes) > 0 { + for _, r := range lo.OmitLogWithMessageRegexes { if r.MatchString(*msg) { return true } @@ -51,10 +51,10 @@ func (lo LoggerOpts) ShouldOmit(msg *string, argSlices ...[]interface{}) bool { // based on the LoggerOpts configuration. // // Note that the given input is changed-in-place by this method. -func (lo LoggerOpts) ApplyMask(msg *string, argSlices ...[]interface{}) { - if len(lo.MaskFieldValueWithFieldKeys) > 0 { - for _, k := range lo.MaskFieldValueWithFieldKeys { - for _, args := range argSlices { +func (lo LoggerOpts) ApplyMask(msg *string, hclogArgSlices ...[]interface{}) { + if len(lo.MaskFieldValuesWithFieldKeys) > 0 { + for _, k := range lo.MaskFieldValuesWithFieldKeys { + for _, args := range hclogArgSlices { // Here we loop `i` with steps of 2, starting from position 1 (i.e. `1, 3, 5, 7...`). // We then look up the key for each argument, by looking at `i-1`. // This ensures that in case of malformed arg slices that don't have @@ -77,8 +77,8 @@ func (lo LoggerOpts) ApplyMask(msg *string, argSlices ...[]interface{}) { // Replace any part of the log message matching any of the configured regexp, // with a masking replacement string - if len(lo.MaskMessageRegex) > 0 { - for _, r := range lo.MaskMessageRegex { + if len(lo.MaskMessageRegexes) > 0 { + for _, r := range lo.MaskMessageRegexes { *msg = r.ReplaceAllString(*msg, logMaskingReplacementString) } } diff --git a/internal/logging/filtering_test.go b/internal/logging/filtering_test.go index 4f77858..d7c1fb2 100644 --- a/internal/logging/filtering_test.go +++ b/internal/logging/filtering_test.go @@ -15,13 +15,13 @@ func TestShouldOmit(t *testing.T) { testCases := map[string]struct { lOpts LoggerOpts msg string - argSlices [][]interface{} + hclogArgSlices [][]interface{} expectedToOmit bool }{ "empty-opts": { lOpts: LoggerOpts{}, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -34,7 +34,7 @@ func TestShouldOmit(t *testing.T) { OmitLogWithFieldKeys: []string{"k2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -47,7 +47,7 @@ func TestShouldOmit(t *testing.T) { OmitLogWithFieldKeys: []string{"K2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -60,7 +60,7 @@ func TestShouldOmit(t *testing.T) { OmitLogWithFieldKeys: []string{"k3"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -70,10 +70,10 @@ func TestShouldOmit(t *testing.T) { }, "omit-log-matching-regexp-case-insensitive": { lOpts: LoggerOpts{ - OmitLogWithMessageRegex: []*regexp.Regexp{regexp.MustCompile("(?i)(foo|bar)")}, + OmitLogWithMessageRegexes: []*regexp.Regexp{regexp.MustCompile("(?i)(foo|bar)")}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -83,10 +83,10 @@ func TestShouldOmit(t *testing.T) { }, "do-not-omit-log-matching-regexp-case-sensitive": { lOpts: LoggerOpts{ - OmitLogWithMessageRegex: []*regexp.Regexp{regexp.MustCompile("(foo|bar)")}, + OmitLogWithMessageRegexes: []*regexp.Regexp{regexp.MustCompile("(foo|bar)")}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -102,7 +102,7 @@ func TestShouldOmit(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - got := testCase.lOpts.ShouldOmit(&testCase.msg, testCase.argSlices...) + got := testCase.lOpts.ShouldOmit(&testCase.msg, testCase.hclogArgSlices...) if got != testCase.expectedToOmit { t.Errorf("expected ShouldOmit to return %t, got %t", testCase.expectedToOmit, got) @@ -117,14 +117,14 @@ func TestApplyMask(t *testing.T) { testCases := map[string]struct { lOpts LoggerOpts msg string - argSlices [][]interface{} + hclogArgSlices [][]interface{} expectedMsg string expectedArgSlices [][]interface{} }{ "empty-opts": { lOpts: LoggerOpts{}, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -140,10 +140,10 @@ func TestApplyMask(t *testing.T) { }, "mask-log-by-key": { lOpts: LoggerOpts{ - MaskFieldValueWithFieldKeys: []string{"k2"}, + MaskFieldValuesWithFieldKeys: []string{"k2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -159,10 +159,10 @@ func TestApplyMask(t *testing.T) { }, "no-mask-log-by-key-if-case-mismatches": { lOpts: LoggerOpts{ - MaskFieldValueWithFieldKeys: []string{"K2"}, + MaskFieldValuesWithFieldKeys: []string{"K2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -178,10 +178,10 @@ func TestApplyMask(t *testing.T) { }, "mask-log-by-non-even-args-cannot-mask-missing-value": { lOpts: LoggerOpts{ - MaskFieldValueWithFieldKeys: []string{"k2", "k4"}, + MaskFieldValuesWithFieldKeys: []string{"k2", "k4"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -205,10 +205,10 @@ func TestApplyMask(t *testing.T) { }, "mask-log-by-non-even-args": { lOpts: LoggerOpts{ - MaskFieldValueWithFieldKeys: []string{"k2"}, + MaskFieldValuesWithFieldKeys: []string{"k2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -228,10 +228,10 @@ func TestApplyMask(t *testing.T) { }, "mask-log-matching-regexp-case-insensitive": { lOpts: LoggerOpts{ - MaskMessageRegex: []*regexp.Regexp{regexp.MustCompile("(?i)(foo|bar)")}, + MaskMessageRegexes: []*regexp.Regexp{regexp.MustCompile("(?i)(foo|bar)")}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -247,10 +247,10 @@ func TestApplyMask(t *testing.T) { }, "mask-log-matching-regexp-case-sensitive": { lOpts: LoggerOpts{ - MaskMessageRegex: []*regexp.Regexp{regexp.MustCompile("incorrectly configured BAZ")}, + MaskMessageRegexes: []*regexp.Regexp{regexp.MustCompile("incorrectly configured BAZ")}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -266,11 +266,11 @@ func TestApplyMask(t *testing.T) { }, "mask-log-by-key-and-matching-regexp": { lOpts: LoggerOpts{ - MaskMessageRegex: []*regexp.Regexp{regexp.MustCompile("incorrectly configured BAZ")}, - MaskFieldValueWithFieldKeys: []string{"k1", "k2"}, + MaskMessageRegexes: []*regexp.Regexp{regexp.MustCompile("incorrectly configured BAZ")}, + MaskFieldValuesWithFieldKeys: []string{"k1", "k2"}, }, msg: testLogMsg, - argSlices: [][]interface{}{ + hclogArgSlices: [][]interface{}{ { "k1", "v1", "k2", "v2", @@ -292,13 +292,13 @@ func TestApplyMask(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - testCase.lOpts.ApplyMask(&testCase.msg, testCase.argSlices...) + testCase.lOpts.ApplyMask(&testCase.msg, testCase.hclogArgSlices...) if diff := cmp.Diff(testCase.msg, testCase.expectedMsg); diff != "" { t.Errorf("unexpected difference detected in log message: %s", diff) } - if diff := cmp.Diff(testCase.argSlices, testCase.expectedArgSlices); diff != "" { + if diff := cmp.Diff(testCase.hclogArgSlices, testCase.expectedArgSlices); diff != "" { t.Errorf("unexpected difference detected in log arguments: %s", diff) } }) diff --git a/internal/logging/options.go b/internal/logging/options.go index a1467dd..f79ea24 100644 --- a/internal/logging/options.go +++ b/internal/logging/options.go @@ -47,30 +47,30 @@ type LoggerOpts struct { IncludeRootFields bool // OmitLogWithFieldKeys indicates that the logger should omit to write - // any log when any of the given keys is found within the arguments. + // any log when any of the given keys is found within the fields. // // Example: // // OmitLogWithFieldKeys = `['foo', 'baz']` // - // log1 = `{ msg = "...", args = { 'foo', '...', 'bar', '...' }` -> omitted - // log2 = `{ msg = "...", args = { 'bar', '...' }` -> printed - // log3 = `{ msg = "...", args = { 'baz`', '...', 'boo', '...' }` -> omitted + // log1 = `{ msg = "...", fields = { 'foo', '...', 'bar', '...' }` -> omitted + // log2 = `{ msg = "...", fields = { 'bar', '...' }` -> printed + // log3 = `{ msg = "...", fields = { 'baz`', '...', 'boo', '...' }` -> omitted // OmitLogWithFieldKeys []string - // OmitLogWithMessageRegex indicates that the logger should omit to write + // OmitLogWithMessageRegexes indicates that the logger should omit to write // any log that matches any of the given *regexp.Regexp. // // Example: // - // OmitLogWithMessageRegex = `[regexp.MustCompile("(foo|bar)")]` + // OmitLogWithMessageRegexes = `[regexp.MustCompile("(foo|bar)")]` // - // log1 = `{ msg = "banana apple foo", args = {...}` -> omitted - // log2 = `{ msg = "pineapple mango", args = {...}` -> printed - // log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted + // log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted + // log2 = `{ msg = "pineapple mango", fields = {...}` -> printed + // log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // - OmitLogWithMessageRegex []*regexp.Regexp + OmitLogWithMessageRegexes []*regexp.Regexp // OmitLogWithMessageStrings indicates that the logger should omit to write // any log that matches any of the given string. @@ -79,37 +79,37 @@ type LoggerOpts struct { // // OmitLogWithMessageStrings = `['foo', 'bar']` // - // log1 = `{ msg = "banana apple foo", args = {...}` -> omitted - // log2 = `{ msg = "pineapple mango", args = {...}` -> printed - // log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted + // log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted + // log2 = `{ msg = "pineapple mango", fields = {...}` -> printed + // log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // OmitLogWithMessageStrings []string - // MaskFieldValueWithFieldKeys indicates that the logger should mask with asterisks (`*`) - // any argument value where the key matches one of the given keys. + // MaskFieldValuesWithFieldKeys indicates that the logger should mask with asterisks (`*`) + // any field value where the key matches one of the given keys. // // Example: // - // MaskFieldValueWithFieldKeys = `['foo', 'baz']` + // MaskFieldValuesWithFieldKeys = `['foo', 'baz']` // - // log1 = `{ msg = "...", args = { 'foo', '***', 'bar', '...' }` -> masked value - // log2 = `{ msg = "...", args = { 'bar', '...' }` -> as-is value - // log3 = `{ msg = "...", args = { 'baz`', '***', 'boo', '...' }` -> masked value + // log1 = `{ msg = "...", fields = { 'foo', '***', 'bar', '...' }` -> masked value + // log2 = `{ msg = "...", fields = { 'bar', '...' }` -> as-is value + // log3 = `{ msg = "...", fields = { 'baz`', '***', 'boo', '...' }` -> masked value // - MaskFieldValueWithFieldKeys []string + MaskFieldValuesWithFieldKeys []string - // MaskMessageRegex indicates that the logger should replace, within + // MaskMessageRegexes indicates that the logger should replace, within // a log message, the portion matching one of the given *regexp.Regexp. // // Example: // - // MaskMessageRegex = `[regexp.MustCompile("(foo|bar)")]` + // MaskMessageRegexes = `[regexp.MustCompile("(foo|bar)")]` // - // log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion - // log2 = `{ msg = "pineapple mango", args = {...}` -> as-is - // log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion + // log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion + // log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is + // log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // - MaskMessageRegex []*regexp.Regexp + MaskMessageRegexes []*regexp.Regexp // MaskMessageStrings indicates that the logger should replace, within // a log message, the portion matching one of the given strings. @@ -118,9 +118,9 @@ type LoggerOpts struct { // // MaskMessageStrings = `['foo', 'bar']` // - // log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion - // log2 = `{ msg = "pineapple mango", args = {...}` -> as-is - // log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion + // log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion + // log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is + // log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // MaskMessageStrings []string } @@ -202,10 +202,10 @@ func WithOmitLogWithFieldKeys(keys ...string) Option { } } -// WithOmitLogWithMessageRegex appends *regexp.Regexp to the LoggerOpts.OmitLogWithMessageRegex field. -func WithOmitLogWithMessageRegex(expressions ...*regexp.Regexp) Option { +// WithOmitLogWithMessageRegexes appends *regexp.Regexp to the LoggerOpts.OmitLogWithMessageRegexes field. +func WithOmitLogWithMessageRegexes(expressions ...*regexp.Regexp) Option { return func(l LoggerOpts) LoggerOpts { - l.OmitLogWithMessageRegex = append(l.OmitLogWithMessageRegex, expressions...) + l.OmitLogWithMessageRegexes = append(l.OmitLogWithMessageRegexes, expressions...) return l } } @@ -218,18 +218,18 @@ func WithOmitLogWithMessageStrings(matchingStrings ...string) Option { } } -// WithMaskFieldValueWithFieldKeys appends keys to the LoggerOpts.MaskFieldValueWithFieldKeys field. -func WithMaskFieldValueWithFieldKeys(keys ...string) Option { +// WithMaskFieldValuesWithFieldKeys appends keys to the LoggerOpts.MaskFieldValuesWithFieldKeys field. +func WithMaskFieldValuesWithFieldKeys(keys ...string) Option { return func(l LoggerOpts) LoggerOpts { - l.MaskFieldValueWithFieldKeys = append(l.MaskFieldValueWithFieldKeys, keys...) + l.MaskFieldValuesWithFieldKeys = append(l.MaskFieldValuesWithFieldKeys, keys...) return l } } -// WithMaskMessageRegex appends *regexp.Regexp to the LoggerOpts.MaskMessageRegex field. -func WithMaskMessageRegex(expressions ...*regexp.Regexp) Option { +// WithMaskMessageRegexes appends *regexp.Regexp to the LoggerOpts.MaskMessageRegexes field. +func WithMaskMessageRegexes(expressions ...*regexp.Regexp) Option { return func(l LoggerOpts) LoggerOpts { - l.MaskMessageRegex = append(l.MaskMessageRegex, expressions...) + l.MaskMessageRegexes = append(l.MaskMessageRegexes, expressions...) return l } } diff --git a/tflog/options_test.go b/tflog/options_test.go index aeff92b..ca90223 100644 --- a/tflog/options_test.go +++ b/tflog/options_test.go @@ -175,13 +175,13 @@ func TestWithRootFields(t *testing.T) { ctx = loggertest.ProviderRoot(ctx, &outputBuffer) for key, value := range testCase.rootFields { - ctx = tflog.With(ctx, key, value) + ctx = tflog.SetField(ctx, key, value) } ctx = tflog.NewSubsystem(ctx, testSubsystem, tflog.WithRootFields()) for key, value := range testCase.subsystemFields { - ctx = tflog.SubsystemWith(ctx, testSubsystem, key, value) + ctx = tflog.SubsystemSetField(ctx, testSubsystem, key, value) } tflog.SubsystemTrace(ctx, testSubsystem, testCase.logMessage) diff --git a/tflog/provider.go b/tflog/provider.go index 8da74d8..c5ef4a5 100644 --- a/tflog/provider.go +++ b/tflog/provider.go @@ -9,9 +9,9 @@ import ( "github.com/hashicorp/terraform-plugin-log/internal/logging" ) -// With returns a new context.Context that has a modified logger in it which -// will include key and value as arguments in all its log output. -func With(ctx context.Context, key string, value interface{}) context.Context { +// SetField returns a new context.Context that has a modified logger in it which +// will include key and value as fields in all its log output. +func SetField(ctx context.Context, key string, value interface{}) context.Context { logger := logging.GetProviderRootLogger(ctx) if logger == nil { // this essentially should never happen in production @@ -26,7 +26,7 @@ func With(ctx context.Context, key string, value interface{}) context.Context { // Trace logs `msg` at the trace level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Trace(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderRootLogger(ctx) @@ -49,7 +49,7 @@ func Trace(ctx context.Context, msg string, additionalFields ...map[string]inter // Debug logs `msg` at the debug level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Debug(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderRootLogger(ctx) @@ -72,7 +72,7 @@ func Debug(ctx context.Context, msg string, additionalFields ...map[string]inter // Info logs `msg` at the info level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Info(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderRootLogger(ctx) @@ -95,7 +95,7 @@ func Info(ctx context.Context, msg string, additionalFields ...map[string]interf // Warn logs `msg` at the warn level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Warn(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderRootLogger(ctx) @@ -118,7 +118,7 @@ func Warn(ctx context.Context, msg string, additionalFields ...map[string]interf // Error logs `msg` at the error level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Error(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderRootLogger(ctx) @@ -154,9 +154,9 @@ func omitOrMask(ctx context.Context, logger hclog.Logger, msg *string, additiona return additionalArgs, false } -// WithOmitLogWithFieldKeys returns a new context.Context that has a modified logger +// OmitLogWithFieldKeys returns a new context.Context that has a modified logger // that will omit to write any log when any of the given keys is found -// within the arguments. +// within its fields. // // Each call to this function is additive: // the keys to omit by are added to the existing configuration. @@ -165,11 +165,11 @@ func omitOrMask(ctx context.Context, logger hclog.Logger, msg *string, additiona // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '...', 'bar', '...' }` -> omitted -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> printed -// log3 = `{ msg = "...", args = { 'baz`', '...', 'boo', '...' }` -> omitted +// log1 = `{ msg = "...", fields = { 'foo', '...', 'bar', '...' }` -> omitted +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> printed +// log3 = `{ msg = "...", fields = { 'baz`', '...', 'boo', '...' }` -> omitted // -func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Context { +func OmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) lOpts = logging.WithOmitLogWithFieldKeys(keys...)(lOpts) @@ -177,7 +177,7 @@ func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Conte return logging.SetProviderRootTFLoggerOpts(ctx, lOpts) } -// WithOmitLogWithMessageRegex returns a new context.Context that has a modified logger +// OmitLogWithMessageRegexes returns a new context.Context that has a modified logger // that will omit to write any log that has a message matching any of the // given *regexp.Regexp. // @@ -188,19 +188,19 @@ func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Conte // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func WithOmitLogWithMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) context.Context { +func OmitLogWithMessageRegexes(ctx context.Context, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) - lOpts = logging.WithOmitLogWithMessageRegex(expressions...)(lOpts) + lOpts = logging.WithOmitLogWithMessageRegexes(expressions...)(lOpts) return logging.SetProviderRootTFLoggerOpts(ctx, lOpts) } -// WithOmitLogMatchingString returns a new context.Context that has a modified logger +// OmitLogWithMessageStrings returns a new context.Context that has a modified logger // that will omit to write any log that matches any of the given string. // // Each call to this function is additive: @@ -210,11 +210,11 @@ func WithOmitLogWithMessageRegex(ctx context.Context, expressions ...*regexp.Reg // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) context.Context { +func OmitLogWithMessageStrings(ctx context.Context, matchingStrings ...string) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) lOpts = logging.WithOmitLogWithMessageStrings(matchingStrings...)(lOpts) @@ -222,8 +222,8 @@ func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) c return logging.SetProviderRootTFLoggerOpts(ctx, lOpts) } -// WithMaskFieldValueWithFieldKeys returns a new context.Context that has a modified logger -// that masks (replaces) with asterisks (`***`) any argument value where the +// MaskFieldValuesWithFieldKeys returns a new context.Context that has a modified logger +// that masks (replaces) with asterisks (`***`) any field value where the // key matches one of the given keys. // // Each call to this function is additive: @@ -233,19 +233,19 @@ func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) c // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '***', 'bar', '...' }` -> masked value -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> as-is value -// log3 = `{ msg = "...", args = { 'baz`', '***', 'boo', '...' }` -> masked value +// log1 = `{ msg = "...", fields = { 'foo', '***', 'bar', '...' }` -> masked value +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> as-is value +// log3 = `{ msg = "...", fields = { 'baz`', '***', 'boo', '...' }` -> masked value // -func WithMaskFieldValueWithFieldKeys(ctx context.Context, keys ...string) context.Context { +func MaskFieldValuesWithFieldKeys(ctx context.Context, keys ...string) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) - lOpts = logging.WithMaskFieldValueWithFieldKeys(keys...)(lOpts) + lOpts = logging.WithMaskFieldValuesWithFieldKeys(keys...)(lOpts) return logging.SetProviderRootTFLoggerOpts(ctx, lOpts) } -// WithMaskMessageRegex returns a new context.Context that has a modified logger +// MaskMessageRegexes returns a new context.Context that has a modified logger // that masks (replaces) with asterisks (`***`) all message substrings matching one // of the given strings. // @@ -256,19 +256,19 @@ func WithMaskFieldValueWithFieldKeys(ctx context.Context, keys ...string) contex // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func WithMaskMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) context.Context { +func MaskMessageRegexes(ctx context.Context, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) - lOpts = logging.WithMaskMessageRegex(expressions...)(lOpts) + lOpts = logging.WithMaskMessageRegexes(expressions...)(lOpts) return logging.SetProviderRootTFLoggerOpts(ctx, lOpts) } -// WithMaskLogMatchingString returns a new context.Context that has a modified logger +// MaskMessageStrings returns a new context.Context that has a modified logger // that masks (replace) with asterisks (`***`) all message substrings equal to one // of the given strings. // @@ -279,11 +279,11 @@ func WithMaskMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) co // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func WithMaskLogMatchingString(ctx context.Context, matchingStrings ...string) context.Context { +func MaskMessageStrings(ctx context.Context, matchingStrings ...string) context.Context { lOpts := logging.GetProviderRootTFLoggerOpts(ctx) lOpts = logging.WithMaskMessageStrings(matchingStrings...)(lOpts) diff --git a/tflog/provider_example_test.go b/tflog/provider_example_test.go index b02036a..6192eef 100644 --- a/tflog/provider_example_test.go +++ b/tflog/provider_example_test.go @@ -15,7 +15,7 @@ func getExampleContext() context.Context { WithoutLocation(), logging.WithoutTimestamp()) } -func ExampleWith() { +func ExampleSetField() { // virtually no plugin developers will need to worry about // instantiating loggers, as the libraries they're using will take care // of that, but we're not using those libraries in these examples. So @@ -26,7 +26,7 @@ func ExampleWith() { exampleCtx := getExampleContext() // non-example-setup code begins here - derivedCtx := With(exampleCtx, "foo", 123) + derivedCtx := SetField(exampleCtx, "foo", 123) // all messages logged with derivedCtx will now have foo=123 // automatically included diff --git a/tflog/provider_test.go b/tflog/provider_test.go index a18c6c9..89fb18a 100644 --- a/tflog/provider_test.go +++ b/tflog/provider_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) -func TestWith(t *testing.T) { +func TestSetField(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -81,7 +81,7 @@ func TestWith(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.With(ctx, testCase.key, testCase.value) + ctx = tflog.SetField(ctx, testCase.key, testCase.value) tflog.Trace(ctx, testCase.logMessage, testCase.additionalFields...) @@ -565,7 +565,7 @@ func TestError(t *testing.T) { const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ" -func TestWithOmitLogWithFieldKeys(t *testing.T) { +func TestOmitLogWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -633,7 +633,7 @@ func TestWithOmitLogWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithOmitLogWithFieldKeys(ctx, testCase.omitLogKeys...) + ctx = tflog.OmitLogWithFieldKeys(ctx, testCase.omitLogKeys...) tflog.Warn(ctx, testCase.msg, testCase.additionalFields...) @@ -649,7 +649,7 @@ func TestWithOmitLogWithFieldKeys(t *testing.T) { } } -func TestWithOmitLogWithMessageRegex(t *testing.T) { +func TestOmitLogWithMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -717,7 +717,7 @@ func TestWithOmitLogWithMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithOmitLogWithMessageRegex(ctx, testCase.omitLogMatchingRegexp...) + ctx = tflog.OmitLogWithMessageRegexes(ctx, testCase.omitLogMatchingRegexp...) tflog.Debug(ctx, testCase.msg, testCase.additionalFields...) @@ -733,7 +733,7 @@ func TestWithOmitLogWithMessageRegex(t *testing.T) { } } -func TestWithOmitLogMatchingString(t *testing.T) { +func TestOmitLogWithMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -801,7 +801,7 @@ func TestWithOmitLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithOmitLogMatchingString(ctx, testCase.omitLogMatchingString...) + ctx = tflog.OmitLogWithMessageStrings(ctx, testCase.omitLogMatchingString...) tflog.Debug(ctx, testCase.msg, testCase.additionalFields...) @@ -817,7 +817,7 @@ func TestWithOmitLogMatchingString(t *testing.T) { } } -func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { +func TestMaskFieldValuesWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -893,7 +893,7 @@ func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithMaskFieldValueWithFieldKeys(ctx, testCase.maskLogKeys...) + ctx = tflog.MaskFieldValuesWithFieldKeys(ctx, testCase.maskLogKeys...) tflog.Error(ctx, testCase.msg, testCase.additionalFields...) @@ -909,7 +909,7 @@ func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { } } -func TestWithMaskMessageRegex(t *testing.T) { +func TestMaskMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -985,7 +985,7 @@ func TestWithMaskMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithMaskMessageRegex(ctx, testCase.maskLogMatchingRegexp...) + ctx = tflog.MaskMessageRegexes(ctx, testCase.maskLogMatchingRegexp...) tflog.Trace(ctx, testCase.msg, testCase.additionalFields...) @@ -1001,7 +1001,7 @@ func TestWithMaskMessageRegex(t *testing.T) { } } -func TestWithMaskLogMatchingString(t *testing.T) { +func TestMaskMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -1077,7 +1077,7 @@ func TestWithMaskLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) - ctx = tflog.WithMaskLogMatchingString(ctx, testCase.maskLogMatchingString...) + ctx = tflog.MaskMessageStrings(ctx, testCase.maskLogMatchingString...) tflog.Info(ctx, testCase.msg, testCase.additionalFields...) diff --git a/tflog/subsystem.go b/tflog/subsystem.go index cce37f5..3f6226e 100644 --- a/tflog/subsystem.go +++ b/tflog/subsystem.go @@ -73,10 +73,10 @@ func NewSubsystem(ctx context.Context, subsystem string, options ...logging.Opti return logging.SetProviderSubsystemLogger(ctx, subsystem, subLogger) } -// SubsystemWith returns a new context.Context that has a modified logger for -// the specified subsystem in it which will include key and value as arguments +// SubsystemSetField returns a new context.Context that has a modified logger for +// the specified subsystem in it which will include key and value as fields // in all its log output. -func SubsystemWith(ctx context.Context, subsystem, key string, value interface{}) context.Context { +func SubsystemSetField(ctx context.Context, subsystem, key string, value interface{}) context.Context { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) if logger == nil { if logging.GetProviderRootLogger(ctx) == nil { @@ -93,7 +93,7 @@ func SubsystemWith(ctx context.Context, subsystem, key string, value interface{} // SubsystemTrace logs `msg` at the trace level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemTrace(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) @@ -118,7 +118,7 @@ func SubsystemTrace(ctx context.Context, subsystem, msg string, additionalFields // SubsystemDebug logs `msg` at the debug level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemDebug(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) @@ -143,7 +143,7 @@ func SubsystemDebug(ctx context.Context, subsystem, msg string, additionalFields // SubsystemInfo logs `msg` at the info level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemInfo(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) @@ -168,7 +168,7 @@ func SubsystemInfo(ctx context.Context, subsystem, msg string, additionalFields // SubsystemWarn logs `msg` at the warn level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemWarn(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) @@ -193,7 +193,7 @@ func SubsystemWarn(ctx context.Context, subsystem, msg string, additionalFields // SubsystemError logs `msg` at the error level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemError(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetProviderSubsystemLogger(ctx, subsystem) @@ -230,9 +230,9 @@ func subsystemOmitOrMask(ctx context.Context, logger hclog.Logger, subsystem str return additionalArgs, false } -// SubsystemWithOmitLogWithFieldKeys returns a new context.Context that has a modified logger +// SubsystemOmitLogWithFieldKeys returns a new context.Context that has a modified logger // that will omit to write any log when any of the given keys is found -// within the arguments. +// within its fields. // // Each call to this function is additive: // the keys to omit by are added to the existing configuration. @@ -241,11 +241,11 @@ func subsystemOmitOrMask(ctx context.Context, logger hclog.Logger, subsystem str // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '...', 'bar', '...' }` -> omitted -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> printed -// log3 = `{ msg = "...", args = { 'baz`', '...', 'boo', '...' }` -> omitted +// log1 = `{ msg = "...", fields = { 'foo', '...', 'bar', '...' }` -> omitted +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> printed +// log3 = `{ msg = "...", fields = { 'baz`', '...', 'boo', '...' }` -> omitted // -func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { +func SubsystemOmitLogWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithOmitLogWithFieldKeys(keys...)(lOpts) @@ -253,7 +253,7 @@ func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, ke return logging.SetProviderSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithOmitLogWithMessageRegex returns a new context.Context that has a modified logger +// SubsystemOmitLogWithMessageRegexes returns a new context.Context that has a modified logger // that will omit to write any log that has a message matching any of the // given *regexp.Regexp. // @@ -264,19 +264,19 @@ func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, ke // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func SubsystemWithOmitLogWithMessageRegex(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { +func SubsystemOmitLogWithMessageRegexes(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithOmitLogWithMessageRegex(expressions...)(lOpts) + lOpts = logging.WithOmitLogWithMessageRegexes(expressions...)(lOpts) return logging.SetProviderSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithOmitLogMatchingString returns a new context.Context that has a modified logger +// SubsystemOmitLogWithMessageStrings returns a new context.Context that has a modified logger // that will omit to write any log that matches any of the given string. // // Each call to this function is additive: @@ -286,11 +286,11 @@ func SubsystemWithOmitLogWithMessageRegex(ctx context.Context, subsystem string, // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { +func SubsystemOmitLogWithMessageStrings(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithOmitLogWithMessageStrings(matchingStrings...)(lOpts) @@ -298,7 +298,7 @@ func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, m return logging.SetProviderSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskFieldValueWithFieldKeys returns a new context.Context that has a modified logger +// SubsystemMaskFieldValuesWithFieldKeys returns a new context.Context that has a modified logger // that masks (replaces) with asterisks (`***`) any argument value where the // key matches one of the given keys. // @@ -309,19 +309,19 @@ func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, m // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '***', 'bar', '...' }` -> masked value -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> as-is value -// log3 = `{ msg = "...", args = { 'baz`', '***', 'boo', '...' }` -> masked value +// log1 = `{ msg = "...", fields = { 'foo', '***', 'bar', '...' }` -> masked value +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> as-is value +// log3 = `{ msg = "...", fields = { 'baz`', '***', 'boo', '...' }` -> masked value // -func SubsystemWithMaskFieldValueWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { +func SubsystemMaskFieldValuesWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithMaskFieldValueWithFieldKeys(keys...)(lOpts) + lOpts = logging.WithMaskFieldValuesWithFieldKeys(keys...)(lOpts) return logging.SetProviderSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskMessageRegex returns a new context.Context that has a modified logger +// SubsystemMaskMessageRegexes returns a new context.Context that has a modified logger // that masks (replaces) with asterisks (`***`) all message substrings matching one // of the given strings. // @@ -332,19 +332,19 @@ func SubsystemWithMaskFieldValueWithFieldKeys(ctx context.Context, subsystem str // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func SubsystemWithMaskMessageRegex(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { +func SubsystemMaskMessageRegexes(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithMaskMessageRegex(expressions...)(lOpts) + lOpts = logging.WithMaskMessageRegexes(expressions...)(lOpts) return logging.SetProviderSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskLogMatchingString returns a new context.Context that has a modified logger +// SubsystemMaskMessageStrings returns a new context.Context that has a modified logger // that masks (replace) with asterisks (`***`) all message substrings equal to one // of the given strings. // @@ -355,11 +355,11 @@ func SubsystemWithMaskMessageRegex(ctx context.Context, subsystem string, expres // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func SubsystemWithMaskLogMatchingString(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { +func SubsystemMaskMessageStrings(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { lOpts := logging.GetProviderSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithMaskMessageStrings(matchingStrings...)(lOpts) diff --git a/tflog/subsystem_example_test.go b/tflog/subsystem_example_test.go index fcb0b0c..f58cc2b 100644 --- a/tflog/subsystem_example_test.go +++ b/tflog/subsystem_example_test.go @@ -60,7 +60,7 @@ func ExampleNewSubsystem_withLevel() { // {"@level":"warn","@message":"hello, world","@module":"provider.my-subsystem","foo":123} } -func ExampleSubsystemWith() { +func ExampleSubsystemSetField() { // virtually no plugin developers will need to worry about // instantiating loggers, as the libraries they're using will take care // of that, but we're not using those libraries in these examples. So @@ -76,7 +76,7 @@ func ExampleSubsystemWith() { // non-example-setup code begins here // associate a key and value with all lines logged by the sub-logger - derivedCtx := SubsystemWith(exampleCtx, "my-subsystem", "foo", 123) + derivedCtx := SubsystemSetField(exampleCtx, "my-subsystem", "foo", 123) // all messages logged with derivedCtx will now have foo=123 // automatically included diff --git a/tflog/subsystem_test.go b/tflog/subsystem_test.go index acf35e9..6fe763d 100644 --- a/tflog/subsystem_test.go +++ b/tflog/subsystem_test.go @@ -16,7 +16,7 @@ const ( testSubsystemModule = "provider." + testSubsystem ) -func TestSubsystemWith(t *testing.T) { +func TestSubsystemSetField(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -87,7 +87,7 @@ func TestSubsystemWith(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWith(ctx, testSubsystem, testCase.key, testCase.value) + ctx = tflog.SubsystemSetField(ctx, testSubsystem, testCase.key, testCase.value) tflog.SubsystemTrace(ctx, testSubsystem, testCase.logMessage, testCase.additionalFields...) @@ -574,7 +574,7 @@ func TestSubsystemError(t *testing.T) { } } -func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { +func TestSubsystemOmitLogWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -643,7 +643,7 @@ func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithOmitLogWithFieldKeys(ctx, testSubsystem, testCase.omitLogKeys...) + ctx = tflog.SubsystemOmitLogWithFieldKeys(ctx, testSubsystem, testCase.omitLogKeys...) tflog.SubsystemWarn(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -659,7 +659,7 @@ func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { } } -func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { +func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -728,7 +728,7 @@ func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithOmitLogWithMessageRegex(ctx, testSubsystem, testCase.omitLogMatchingRegexp...) + ctx = tflog.SubsystemOmitLogWithMessageRegexes(ctx, testSubsystem, testCase.omitLogMatchingRegexp...) tflog.SubsystemDebug(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -744,7 +744,7 @@ func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { } } -func TestSubsystemWithOmitLogMatchingString(t *testing.T) { +func TestSubsystemOmitLogWithMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -813,7 +813,7 @@ func TestSubsystemWithOmitLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithOmitLogMatchingString(ctx, testSubsystem, testCase.omitLogMatchingString...) + ctx = tflog.SubsystemOmitLogWithMessageStrings(ctx, testSubsystem, testCase.omitLogMatchingString...) tflog.SubsystemDebug(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -829,7 +829,7 @@ func TestSubsystemWithOmitLogMatchingString(t *testing.T) { } } -func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { +func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -906,7 +906,7 @@ func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithMaskFieldValueWithFieldKeys(ctx, testSubsystem, testCase.maskLogKeys...) + ctx = tflog.SubsystemMaskFieldValuesWithFieldKeys(ctx, testSubsystem, testCase.maskLogKeys...) tflog.SubsystemError(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -922,7 +922,7 @@ func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { } } -func TestSubsystemWithMaskMessageRegex(t *testing.T) { +func TestSubsystemMaskMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -999,7 +999,7 @@ func TestSubsystemWithMaskMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithMaskMessageRegex(ctx, testSubsystem, testCase.maskLogMatchingRegexp...) + ctx = tflog.SubsystemMaskMessageRegexes(ctx, testSubsystem, testCase.maskLogMatchingRegexp...) tflog.SubsystemTrace(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -1015,7 +1015,7 @@ func TestSubsystemWithMaskMessageRegex(t *testing.T) { } } -func TestSubsystemWithMaskLogMatchingString(t *testing.T) { +func TestSubsystemMaskMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -1092,7 +1092,7 @@ func TestSubsystemWithMaskLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.ProviderRoot(ctx, &outputBuffer) ctx = tflog.NewSubsystem(ctx, testSubsystem) - ctx = tflog.SubsystemWithMaskLogMatchingString(ctx, testSubsystem, testCase.maskLogMatchingString...) + ctx = tflog.SubsystemMaskMessageStrings(ctx, testSubsystem, testCase.maskLogMatchingString...) tflog.SubsystemInfo(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) diff --git a/tflogtest/json_decode_example_test.go b/tflogtest/json_decode_example_test.go index 2fd48ab..5b7c112 100644 --- a/tflogtest/json_decode_example_test.go +++ b/tflogtest/json_decode_example_test.go @@ -14,7 +14,7 @@ func ExampleMultilineJSONDecode() { ctx := RootLogger(context.Background(), &output) // Root provider logger is now available for usage, such as writing - // entries, calling With(), or calling NewSubsystem(). + // entries, calling SetField(), or calling NewSubsystem(). tflog.Trace(ctx, "entry 1") tflog.Trace(ctx, "entry 2") diff --git a/tflogtest/root_logger_example_test.go b/tflogtest/root_logger_example_test.go index 720269b..0f1c6f5 100644 --- a/tflogtest/root_logger_example_test.go +++ b/tflogtest/root_logger_example_test.go @@ -14,7 +14,7 @@ func ExampleRootLogger() { ctx := RootLogger(context.Background(), &output) // Root provider logger is now available for usage, such as writing - // entries, calling With(), or calling NewSubsystem(). + // entries, calling SetField(), or calling NewSubsystem(). tflog.Trace(ctx, "hello, world", map[string]interface{}{ "foo": 123, "colors": []string{"red", "blue", "green"}, diff --git a/tfsdklog/options_test.go b/tfsdklog/options_test.go index df9902c..ace4536 100644 --- a/tfsdklog/options_test.go +++ b/tfsdklog/options_test.go @@ -175,13 +175,13 @@ func TestWithRootFields(t *testing.T) { ctx = loggertest.SDKRoot(ctx, &outputBuffer) for key, value := range testCase.rootFields { - ctx = tfsdklog.With(ctx, key, value) + ctx = tfsdklog.SetField(ctx, key, value) } ctx = tfsdklog.NewSubsystem(ctx, testSubsystem, tfsdklog.WithRootFields()) for key, value := range testCase.subsystemFields { - ctx = tfsdklog.SubsystemWith(ctx, testSubsystem, key, value) + ctx = tfsdklog.SubsystemSetField(ctx, testSubsystem, key, value) } tfsdklog.SubsystemTrace(ctx, testSubsystem, testCase.logMessage) diff --git a/tfsdklog/sdk.go b/tfsdklog/sdk.go index 0ce8272..3d30a34 100644 --- a/tfsdklog/sdk.go +++ b/tfsdklog/sdk.go @@ -95,9 +95,9 @@ func NewRootProviderLogger(ctx context.Context, options ...logging.Option) conte return ctx } -// With returns a new context.Context that has a modified logger in it which -// will include key and value as arguments in all its log output. -func With(ctx context.Context, key string, value interface{}) context.Context { +// SetField returns a new context.Context that has a modified logger in it which +// will include key and value as fields in all its log output. +func SetField(ctx context.Context, key string, value interface{}) context.Context { logger := logging.GetSDKRootLogger(ctx) if logger == nil { // this essentially should never happen in production the root @@ -111,7 +111,7 @@ func With(ctx context.Context, key string, value interface{}) context.Context { // Trace logs `msg` at the trace level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Trace(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKRootLogger(ctx) @@ -133,7 +133,7 @@ func Trace(ctx context.Context, msg string, additionalFields ...map[string]inter // Debug logs `msg` at the debug level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Debug(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKRootLogger(ctx) @@ -155,7 +155,7 @@ func Debug(ctx context.Context, msg string, additionalFields ...map[string]inter // Info logs `msg` at the info level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Info(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKRootLogger(ctx) @@ -177,7 +177,7 @@ func Info(ctx context.Context, msg string, additionalFields ...map[string]interf // Warn logs `msg` at the warn level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Warn(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKRootLogger(ctx) @@ -199,7 +199,7 @@ func Warn(ctx context.Context, msg string, additionalFields ...map[string]interf // Error logs `msg` at the error level to the logger in `ctx`, with optional // `additionalFields` structured key-value fields in the log output. Fields are -// shallow merged with any defined on the logger, e.g. by the `With()` function, +// shallow merged with any defined on the logger, e.g. by the `SetField()` function, // and across multiple maps. func Error(ctx context.Context, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKRootLogger(ctx) @@ -234,9 +234,9 @@ func omitOrMask(ctx context.Context, logger hclog.Logger, msg *string, additiona return additionalArgs, false } -// WithOmitLogWithFieldKeys returns a new context.Context that has a modified logger +// OmitLogWithFieldKeys returns a new context.Context that has a modified logger // that will omit to write any log when any of the given keys is found -// within the arguments. +// within its fields. // // Each call to this function is additive: // the keys to omit by are added to the existing configuration. @@ -245,11 +245,11 @@ func omitOrMask(ctx context.Context, logger hclog.Logger, msg *string, additiona // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '...', 'bar', '...' }` -> omitted -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> printed -// log3 = `{ msg = "...", args = { 'baz`', '...', 'boo', '...' }` -> omitted +// log1 = `{ msg = "...", fields = { 'foo', '...', 'bar', '...' }` -> omitted +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> printed +// log3 = `{ msg = "...", fields = { 'baz`', '...', 'boo', '...' }` -> omitted // -func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Context { +func OmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) lOpts = logging.WithOmitLogWithFieldKeys(keys...)(lOpts) @@ -257,7 +257,7 @@ func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Conte return logging.SetSDKRootTFLoggerOpts(ctx, lOpts) } -// WithOmitLogWithMessageRegex returns a new context.Context that has a modified logger +// OmitLogWithMessageRegexes returns a new context.Context that has a modified logger // that will omit to write any log that has a message matching any of the // given *regexp.Regexp. // @@ -268,19 +268,19 @@ func WithOmitLogWithFieldKeys(ctx context.Context, keys ...string) context.Conte // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func WithOmitLogWithMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) context.Context { +func OmitLogWithMessageRegexes(ctx context.Context, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) - lOpts = logging.WithOmitLogWithMessageRegex(expressions...)(lOpts) + lOpts = logging.WithOmitLogWithMessageRegexes(expressions...)(lOpts) return logging.SetSDKRootTFLoggerOpts(ctx, lOpts) } -// WithOmitLogMatchingString returns a new context.Context that has a modified logger +// OmitLogWithMessageStrings returns a new context.Context that has a modified logger // that will omit to write any log that matches any of the given string. // // Each call to this function is additive: @@ -290,11 +290,11 @@ func WithOmitLogWithMessageRegex(ctx context.Context, expressions ...*regexp.Reg // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) context.Context { +func OmitLogWithMessageStrings(ctx context.Context, matchingStrings ...string) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) lOpts = logging.WithOmitLogWithMessageStrings(matchingStrings...)(lOpts) @@ -302,8 +302,8 @@ func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) c return logging.SetSDKRootTFLoggerOpts(ctx, lOpts) } -// WithMaskFieldValueWithFieldKeys returns a new context.Context that has a modified logger -// that masks (replaces) with asterisks (`***`) any argument value where the +// MaskFieldValuesWithFieldKeys returns a new context.Context that has a modified logger +// that masks (replaces) with asterisks (`***`) any field value where the // key matches one of the given keys. // // Each call to this function is additive: @@ -313,19 +313,19 @@ func WithOmitLogMatchingString(ctx context.Context, matchingStrings ...string) c // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '***', 'bar', '...' }` -> masked value -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> as-is value -// log3 = `{ msg = "...", args = { 'baz`', '***', 'boo', '...' }` -> masked value +// log1 = `{ msg = "...", fields = { 'foo', '***', 'bar', '...' }` -> masked value +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> as-is value +// log3 = `{ msg = "...", fields = { 'baz`', '***', 'boo', '...' }` -> masked value // -func WithMaskFieldValueWithFieldKeys(ctx context.Context, keys ...string) context.Context { +func MaskFieldValuesWithFieldKeys(ctx context.Context, keys ...string) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) - lOpts = logging.WithMaskFieldValueWithFieldKeys(keys...)(lOpts) + lOpts = logging.WithMaskFieldValuesWithFieldKeys(keys...)(lOpts) return logging.SetSDKRootTFLoggerOpts(ctx, lOpts) } -// WithMaskMessageRegex returns a new context.Context that has a modified logger +// MaskMessageRegexes returns a new context.Context that has a modified logger // that masks (replaces) with asterisks (`***`) all message substrings matching one // of the given strings. // @@ -336,19 +336,19 @@ func WithMaskFieldValueWithFieldKeys(ctx context.Context, keys ...string) contex // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func WithMaskMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) context.Context { +func MaskMessageRegexes(ctx context.Context, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) - lOpts = logging.WithMaskMessageRegex(expressions...)(lOpts) + lOpts = logging.WithMaskMessageRegexes(expressions...)(lOpts) return logging.SetSDKRootTFLoggerOpts(ctx, lOpts) } -// WithMaskLogMatchingString returns a new context.Context that has a modified logger +// MaskMessageStrings returns a new context.Context that has a modified logger // that masks (replace) with asterisks (`***`) all message substrings equal to one // of the given strings. // @@ -359,11 +359,11 @@ func WithMaskMessageRegex(ctx context.Context, expressions ...*regexp.Regexp) co // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func WithMaskLogMatchingString(ctx context.Context, matchingStrings ...string) context.Context { +func MaskMessageStrings(ctx context.Context, matchingStrings ...string) context.Context { lOpts := logging.GetSDKRootTFLoggerOpts(ctx) lOpts = logging.WithMaskMessageStrings(matchingStrings...)(lOpts) diff --git a/tfsdklog/sdk_example_test.go b/tfsdklog/sdk_example_test.go index 16e47ab..dec8a1d 100644 --- a/tfsdklog/sdk_example_test.go +++ b/tfsdklog/sdk_example_test.go @@ -13,7 +13,7 @@ func getExampleContext() context.Context { WithLevel(hclog.Trace), WithoutLocation(), logging.WithoutTimestamp()) } -func ExampleWith() { +func ExampleSetField() { // this function calls New with the options it needs to be reliably // tested. Framework and SDK developers should call New, inject the // resulting context in their framework, and then pass it around. This @@ -22,7 +22,7 @@ func ExampleWith() { exampleCtx := getExampleContext() // non-example-setup code begins here - derivedCtx := With(exampleCtx, "foo", 123) + derivedCtx := SetField(exampleCtx, "foo", 123) // all messages logged with derivedCtx will now have foo=123 // automatically included diff --git a/tfsdklog/sdk_test.go b/tfsdklog/sdk_test.go index 25974d0..ca0cf8e 100644 --- a/tfsdklog/sdk_test.go +++ b/tfsdklog/sdk_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-log/tfsdklog" ) -func TestWith(t *testing.T) { +func TestSetField(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -81,7 +81,7 @@ func TestWith(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.With(ctx, testCase.key, testCase.value) + ctx = tfsdklog.SetField(ctx, testCase.key, testCase.value) tfsdklog.Trace(ctx, testCase.logMessage, testCase.additionalFields...) @@ -565,7 +565,7 @@ func TestError(t *testing.T) { const testLogMsg = "System FOO has caused error BAR because of incorrectly configured BAZ" -func TestWithOmitLogWithFieldKeys(t *testing.T) { +func TestOmitLogWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -633,7 +633,7 @@ func TestWithOmitLogWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithOmitLogWithFieldKeys(ctx, testCase.omitLogKeys...) + ctx = tfsdklog.OmitLogWithFieldKeys(ctx, testCase.omitLogKeys...) tfsdklog.Warn(ctx, testCase.msg, testCase.additionalFields...) @@ -649,7 +649,7 @@ func TestWithOmitLogWithFieldKeys(t *testing.T) { } } -func TestWithOmitLogWithMessageRegex(t *testing.T) { +func TestOmitLogWithMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -717,7 +717,7 @@ func TestWithOmitLogWithMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithOmitLogWithMessageRegex(ctx, testCase.omitLogMatchingRegexp...) + ctx = tfsdklog.OmitLogWithMessageRegexes(ctx, testCase.omitLogMatchingRegexp...) tfsdklog.Debug(ctx, testCase.msg, testCase.additionalFields...) @@ -733,7 +733,7 @@ func TestWithOmitLogWithMessageRegex(t *testing.T) { } } -func TestWithOmitLogMatchingString(t *testing.T) { +func TestOmitLogWithMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -801,7 +801,7 @@ func TestWithOmitLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithOmitLogMatchingString(ctx, testCase.omitLogMatchingString...) + ctx = tfsdklog.OmitLogWithMessageStrings(ctx, testCase.omitLogMatchingString...) tfsdklog.Debug(ctx, testCase.msg, testCase.additionalFields...) @@ -817,7 +817,7 @@ func TestWithOmitLogMatchingString(t *testing.T) { } } -func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { +func TestMaskFieldValuesWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -893,7 +893,7 @@ func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithMaskFieldValueWithFieldKeys(ctx, testCase.maskLogKeys...) + ctx = tfsdklog.MaskFieldValuesWithFieldKeys(ctx, testCase.maskLogKeys...) tfsdklog.Error(ctx, testCase.msg, testCase.additionalFields...) @@ -909,7 +909,7 @@ func TestWithMaskFieldValueWithFieldKeys(t *testing.T) { } } -func TestWithMaskMessageRegex(t *testing.T) { +func TestMaskMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -985,7 +985,7 @@ func TestWithMaskMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithMaskMessageRegex(ctx, testCase.maskLogMatchingRegexp...) + ctx = tfsdklog.MaskMessageRegexes(ctx, testCase.maskLogMatchingRegexp...) tfsdklog.Trace(ctx, testCase.msg, testCase.additionalFields...) @@ -1001,7 +1001,7 @@ func TestWithMaskMessageRegex(t *testing.T) { } } -func TestWithMaskLogMatchingString(t *testing.T) { +func TestMaskMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -1077,7 +1077,7 @@ func TestWithMaskLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) - ctx = tfsdklog.WithMaskLogMatchingString(ctx, testCase.maskLogMatchingString...) + ctx = tfsdklog.MaskMessageStrings(ctx, testCase.maskLogMatchingString...) tfsdklog.Info(ctx, testCase.msg, testCase.additionalFields...) diff --git a/tfsdklog/subsystem.go b/tfsdklog/subsystem.go index 37cef52..bb6ce27 100644 --- a/tfsdklog/subsystem.go +++ b/tfsdklog/subsystem.go @@ -73,10 +73,10 @@ func NewSubsystem(ctx context.Context, subsystem string, options ...logging.Opti return logging.SetSDKSubsystemLogger(ctx, subsystem, subLogger) } -// SubsystemWith returns a new context.Context that has a modified logger for -// the specified subsystem in it which will include key and value as arguments +// SubsystemSetField returns a new context.Context that has a modified logger for +// the specified subsystem in it which will include key and value as fields // in all its log output. -func SubsystemWith(ctx context.Context, subsystem, key string, value interface{}) context.Context { +func SubsystemSetField(ctx context.Context, subsystem, key string, value interface{}) context.Context { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) if logger == nil { if logging.GetSDKRootLogger(ctx) == nil { @@ -93,7 +93,7 @@ func SubsystemWith(ctx context.Context, subsystem, key string, value interface{} // SubsystemTrace logs `msg` at the trace level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemTrace(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) @@ -118,7 +118,7 @@ func SubsystemTrace(ctx context.Context, subsystem, msg string, additionalFields // SubsystemDebug logs `msg` at the debug level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemDebug(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) @@ -143,7 +143,7 @@ func SubsystemDebug(ctx context.Context, subsystem, msg string, additionalFields // SubsystemInfo logs `msg` at the info level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemInfo(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) @@ -168,7 +168,7 @@ func SubsystemInfo(ctx context.Context, subsystem, msg string, additionalFields // SubsystemWarn logs `msg` at the warn level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemWarn(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) @@ -193,7 +193,7 @@ func SubsystemWarn(ctx context.Context, subsystem, msg string, additionalFields // SubsystemError logs `msg` at the error level to the subsystem logger // specified in `ctx`, with optional `additionalFields` structured key-value // fields in the log output. Fields are shallow merged with any defined on the -// subsystem logger, e.g. by the `SubsystemWith()` function, and across +// subsystem logger, e.g. by the `SubsystemSetField()` function, and across // multiple maps. func SubsystemError(ctx context.Context, subsystem, msg string, additionalFields ...map[string]interface{}) { logger := logging.GetSDKSubsystemLogger(ctx, subsystem) @@ -230,9 +230,9 @@ func subsystemOmitOrMask(ctx context.Context, logger hclog.Logger, subsystem str return additionalArgs, false } -// SubsystemWithOmitLogWithFieldKeys returns a new context.Context that has a modified logger +// SubsystemOmitLogWithFieldKeys returns a new context.Context that has a modified logger // that will omit to write any log when any of the given keys is found -// within the arguments. +// within its fields. // // Each call to this function is additive: // the keys to omit by are added to the existing configuration. @@ -241,11 +241,11 @@ func subsystemOmitOrMask(ctx context.Context, logger hclog.Logger, subsystem str // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '...', 'bar', '...' }` -> omitted -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> printed -// log3 = `{ msg = "...", args = { 'baz`', '...', 'boo', '...' }` -> omitted +// log1 = `{ msg = "...", fields = { 'foo', '...', 'bar', '...' }` -> omitted +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> printed +// log3 = `{ msg = "...", fields = { 'baz`', '...', 'boo', '...' }` -> omitted // -func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { +func SubsystemOmitLogWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithOmitLogWithFieldKeys(keys...)(lOpts) @@ -253,7 +253,7 @@ func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, ke return logging.SetSDKSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithOmitLogWithMessageRegex returns a new context.Context that has a modified logger +// SubsystemOmitLogWithMessageRegexes returns a new context.Context that has a modified logger // that will omit to write any log that has a message matching any of the // given *regexp.Regexp. // @@ -264,19 +264,19 @@ func SubsystemWithOmitLogWithFieldKeys(ctx context.Context, subsystem string, ke // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func SubsystemWithOmitLogWithMessageRegex(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { +func SubsystemOmitLogWithMessageRegexes(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithOmitLogWithMessageRegex(expressions...)(lOpts) + lOpts = logging.WithOmitLogWithMessageRegexes(expressions...)(lOpts) return logging.SetSDKSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithOmitLogMatchingString returns a new context.Context that has a modified logger +// SubsystemOmitLogWithMessageStrings returns a new context.Context that has a modified logger // that will omit to write any log that matches any of the given string. // // Each call to this function is additive: @@ -286,11 +286,11 @@ func SubsystemWithOmitLogWithMessageRegex(ctx context.Context, subsystem string, // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple foo", args = {...}` -> omitted -// log2 = `{ msg = "pineapple mango", args = {...}` -> printed -// log3 = `{ msg = "pineapple mango bar", args = {...}` -> omitted +// log1 = `{ msg = "banana apple foo", fields = {...}` -> omitted +// log2 = `{ msg = "pineapple mango", fields = {...}` -> printed +// log3 = `{ msg = "pineapple mango bar", fields = {...}` -> omitted // -func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { +func SubsystemOmitLogWithMessageStrings(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithOmitLogWithMessageStrings(matchingStrings...)(lOpts) @@ -298,8 +298,8 @@ func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, m return logging.SetSDKSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskFieldValueWithFieldKeys returns a new context.Context that has a modified logger -// that masks (replaces) with asterisks (`***`) any argument value where the +// SubsystemMaskFieldValuesWithFieldKeys returns a new context.Context that has a modified logger +// that masks (replaces) with asterisks (`***`) any field value where the // key matches one of the given keys. // // Each call to this function is additive: @@ -309,19 +309,19 @@ func SubsystemWithOmitLogMatchingString(ctx context.Context, subsystem string, m // // configuration = `['foo', 'baz']` // -// log1 = `{ msg = "...", args = { 'foo', '***', 'bar', '...' }` -> masked value -// log2 = `{ msg = "...", args = { 'bar', '...' }` -> as-is value -// log3 = `{ msg = "...", args = { 'baz`', '***', 'boo', '...' }` -> masked value +// log1 = `{ msg = "...", fields = { 'foo', '***', 'bar', '...' }` -> masked value +// log2 = `{ msg = "...", fields = { 'bar', '...' }` -> as-is value +// log3 = `{ msg = "...", fields = { 'baz`', '***', 'boo', '...' }` -> masked value // -func SubsystemWithMaskFieldValueWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { +func SubsystemMaskFieldValuesWithFieldKeys(ctx context.Context, subsystem string, keys ...string) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithMaskFieldValueWithFieldKeys(keys...)(lOpts) + lOpts = logging.WithMaskFieldValuesWithFieldKeys(keys...)(lOpts) return logging.SetSDKSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskMessageRegex returns a new context.Context that has a modified logger +// SubsystemMaskMessageRegexes returns a new context.Context that has a modified logger // that masks (replaces) with asterisks (`***`) all message substrings matching one // of the given strings. // @@ -332,19 +332,19 @@ func SubsystemWithMaskFieldValueWithFieldKeys(ctx context.Context, subsystem str // // configuration = `[regexp.MustCompile("(foo|bar)")]` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func SubsystemWithMaskMessageRegex(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { +func SubsystemMaskMessageRegexes(ctx context.Context, subsystem string, expressions ...*regexp.Regexp) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) - lOpts = logging.WithMaskMessageRegex(expressions...)(lOpts) + lOpts = logging.WithMaskMessageRegexes(expressions...)(lOpts) return logging.SetSDKSubsystemTFLoggerOpts(ctx, subsystem, lOpts) } -// SubsystemWithMaskLogMatchingString returns a new context.Context that has a modified logger +// SubsystemMaskMessageStrings returns a new context.Context that has a modified logger // that masks (replace) with asterisks (`***`) all message substrings equal to one // of the given strings. // @@ -355,11 +355,11 @@ func SubsystemWithMaskMessageRegex(ctx context.Context, subsystem string, expres // // configuration = `['foo', 'bar']` // -// log1 = `{ msg = "banana apple ***", args = {...}` -> masked portion -// log2 = `{ msg = "pineapple mango", args = {...}` -> as-is -// log3 = `{ msg = "pineapple mango ***", args = {...}` -> masked portion +// log1 = `{ msg = "banana apple ***", fields = {...}` -> masked portion +// log2 = `{ msg = "pineapple mango", fields = {...}` -> as-is +// log3 = `{ msg = "pineapple mango ***", fields = {...}` -> masked portion // -func SubsystemWithMaskLogMatchingString(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { +func SubsystemMaskMessageStrings(ctx context.Context, subsystem string, matchingStrings ...string) context.Context { lOpts := logging.GetSDKSubsystemTFLoggerOpts(ctx, subsystem) lOpts = logging.WithMaskMessageStrings(matchingStrings...)(lOpts) diff --git a/tfsdklog/subsystem_example_test.go b/tfsdklog/subsystem_example_test.go index 3cdad32..48be9af 100644 --- a/tfsdklog/subsystem_example_test.go +++ b/tfsdklog/subsystem_example_test.go @@ -52,7 +52,7 @@ func ExampleNewSubsystem_withLevel() { // {"@level":"warn","@message":"hello, world","@module":"sdk.my-subsystem","foo":123} } -func ExampleSubsystemWith() { +func ExampleSubsystemSetField() { // this function calls new with the options it needs to be reliably // tested. framework and sdk developers should call new, inject the // resulting context in their framework, and then pass it around. this @@ -62,7 +62,7 @@ func ExampleSubsystemWith() { exampleCtx = NewSubsystem(exampleCtx, "my-subsystem") // non-example-setup code begins here - derivedCtx := SubsystemWith(exampleCtx, "my-subsystem", "foo", 123) + derivedCtx := SubsystemSetField(exampleCtx, "my-subsystem", "foo", 123) // all messages logged with derivedCtx will now have foo=123 // automatically included diff --git a/tfsdklog/subsystem_test.go b/tfsdklog/subsystem_test.go index ba8f839..c48c580 100644 --- a/tfsdklog/subsystem_test.go +++ b/tfsdklog/subsystem_test.go @@ -16,7 +16,7 @@ const ( testSubsystemModule = "sdk." + testSubsystem ) -func TestSubsystemWith(t *testing.T) { +func TestSubsystemSetField(t *testing.T) { t.Parallel() testCases := map[string]struct { @@ -87,7 +87,7 @@ func TestSubsystemWith(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWith(ctx, testSubsystem, testCase.key, testCase.value) + ctx = tfsdklog.SubsystemSetField(ctx, testSubsystem, testCase.key, testCase.value) tfsdklog.SubsystemTrace(ctx, testSubsystem, testCase.logMessage, testCase.additionalFields...) @@ -574,7 +574,7 @@ func TestSubsystemError(t *testing.T) { } } -func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { +func TestSubsystemOmitLogWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -643,7 +643,7 @@ func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithOmitLogWithFieldKeys(ctx, testSubsystem, testCase.omitLogKeys...) + ctx = tfsdklog.SubsystemOmitLogWithFieldKeys(ctx, testSubsystem, testCase.omitLogKeys...) tfsdklog.SubsystemWarn(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -659,7 +659,7 @@ func TestSubsystemWithOmitLogWithFieldKeys(t *testing.T) { } } -func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { +func TestSubsystemOmitLogWithMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -728,7 +728,7 @@ func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithOmitLogWithMessageRegex(ctx, testSubsystem, testCase.omitLogMatchingRegexp...) + ctx = tfsdklog.SubsystemOmitLogWithMessageRegexes(ctx, testSubsystem, testCase.omitLogMatchingRegexp...) tfsdklog.SubsystemDebug(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -744,7 +744,7 @@ func TestSubsystemWithOmitLogWithMessageRegex(t *testing.T) { } } -func TestSubsystemWithOmitLogMatchingString(t *testing.T) { +func TestSubsystemOmitLogWithMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -813,7 +813,7 @@ func TestSubsystemWithOmitLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithOmitLogMatchingString(ctx, testSubsystem, testCase.omitLogMatchingString...) + ctx = tfsdklog.SubsystemOmitLogWithMessageStrings(ctx, testSubsystem, testCase.omitLogMatchingString...) tfsdklog.SubsystemDebug(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -829,7 +829,7 @@ func TestSubsystemWithOmitLogMatchingString(t *testing.T) { } } -func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { +func TestSubsystemMaskFieldValuesWithFieldKeys(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -906,7 +906,7 @@ func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithMaskFieldValueWithFieldKeys(ctx, testSubsystem, testCase.maskLogKeys...) + ctx = tfsdklog.SubsystemMaskFieldValuesWithFieldKeys(ctx, testSubsystem, testCase.maskLogKeys...) tfsdklog.SubsystemError(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -922,7 +922,7 @@ func TestSubsystemWithMaskFieldValueWithFieldKeys(t *testing.T) { } } -func TestSubsystemWithMaskMessageRegex(t *testing.T) { +func TestSubsystemMaskMessageRegexes(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -999,7 +999,7 @@ func TestSubsystemWithMaskMessageRegex(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithMaskMessageRegex(ctx, testSubsystem, testCase.maskLogMatchingRegexp...) + ctx = tfsdklog.SubsystemMaskMessageRegexes(ctx, testSubsystem, testCase.maskLogMatchingRegexp...) tfsdklog.SubsystemTrace(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) @@ -1015,7 +1015,7 @@ func TestSubsystemWithMaskMessageRegex(t *testing.T) { } } -func TestSubsystemWithMaskLogMatchingString(t *testing.T) { +func TestSubsystemMaskMessageStrings(t *testing.T) { testCases := map[string]struct { msg string additionalFields []map[string]interface{} @@ -1092,7 +1092,7 @@ func TestSubsystemWithMaskLogMatchingString(t *testing.T) { ctx := context.Background() ctx = loggertest.SDKRoot(ctx, &outputBuffer) ctx = tfsdklog.NewSubsystem(ctx, testSubsystem) - ctx = tfsdklog.SubsystemWithMaskLogMatchingString(ctx, testSubsystem, testCase.maskLogMatchingString...) + ctx = tfsdklog.SubsystemMaskMessageStrings(ctx, testSubsystem, testCase.maskLogMatchingString...) tfsdklog.SubsystemInfo(ctx, testSubsystem, testCase.msg, testCase.additionalFields...) diff --git a/tfsdklogtest/json_decode_example_test.go b/tfsdklogtest/json_decode_example_test.go index de9845b..f75bb6c 100644 --- a/tfsdklogtest/json_decode_example_test.go +++ b/tfsdklogtest/json_decode_example_test.go @@ -14,7 +14,7 @@ func ExampleMultilineJSONDecode() { ctx := RootLogger(context.Background(), &output) // Root SDK logger is now available for usage, such as writing entries, - // calling With(), or calling NewSubsystem(). + // calling SetField(), or calling NewSubsystem(). tfsdklog.Trace(ctx, "entry 1") tfsdklog.Trace(ctx, "entry 2") diff --git a/tfsdklogtest/root_logger_example_test.go b/tfsdklogtest/root_logger_example_test.go index c7cf2d6..cbdc270 100644 --- a/tfsdklogtest/root_logger_example_test.go +++ b/tfsdklogtest/root_logger_example_test.go @@ -14,7 +14,7 @@ func ExampleRootLogger() { ctx := RootLogger(context.Background(), &output) // Root SDK logger is now available for usage, such as writing entries, - // calling With(), or calling NewSubsystem(). + // calling SetField(), or calling NewSubsystem(). tfsdklog.Trace(ctx, "hello, world", map[string]interface{}{ "foo": 123, "colors": []string{"red", "blue", "green"}, diff --git a/website/docs/plugin/log/writing.mdx b/website/docs/plugin/log/writing.mdx index 001b84a..a69c6a5 100644 --- a/website/docs/plugin/log/writing.mdx +++ b/website/docs/plugin/log/writing.mdx @@ -92,7 +92,7 @@ tflog.Trace(ctx, "executing API request", map[string]interface{}{ Loggers are transported using a `context.Context` type, so injecting a variable into a logger returns a new `context.Context` containing the modified logger. Subsequent calls to `tflog` with that logger will implicitly include the variable. -Use [`tflog.With()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#With) to attach variables to a logger. +Use [`tflog.SetField()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SetField) to attach variables to a logger. ```go // overwrite logger to include new `url` variable @@ -152,7 +152,7 @@ Logging or adding variables to subsystem loggers requires separate function call * [`tflog.SubsystemInfo()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemInfo): Equivalent to [`tflog.Info()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#Info), but using a subsystem logger. * [`tflog.SubsystemDebug()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemDebug): Equivalent to [`tflog.Debug()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#Debug), but using a subsystem logger. * [`tflog.SubsystemTrace()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemTrace): Equivalent to [`tflog.Trace()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#Trace), but using a subsystem logger. -* [`tflog.SubsystemWith()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemWith): Equivalent to [`tflog.With()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#With), but using a subsystem logger. +* [`tflog.SubsystemSetField()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemSetField): Equivalent to [`tflog.SetField()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SetField), but using a subsystem logger. For example, use [`tflog.SubsystemDebug()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemDebug) to write a debug level log with a specific subsystem. @@ -162,7 +162,7 @@ tflog.SubsystemDebug(ctx, "my-subsystem", "writing to a subsystem", map[string]i }) ``` -Use [`tflog.SubsystemWith()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemWith) to attach variables to a specific subsystem. +Use [`tflog.SubsystemSetField()`](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-log/tflog#SubsystemSetField) to attach variables to a specific subsystem. ```go // overwrite logger to include new `url` variable