mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-14 02:33:21 +02:00
log: Change EnabledParameters to have a field instead of getter and setter (#6009)
Allow users to to write less verbose code by changing methods to field.
This commit is contained in:
parent
9f82e51c89
commit
2f0bf8e095
@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5929)
|
||||
- Propagate non-retryable error messages to client in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#5929)
|
||||
- Performance improvements for attribute value `AsStringSlice`, `AsFloat64Slice`, `AsInt64Slice`, `AsBoolSlice`. (#6011)
|
||||
- Change `EnabledParameters` to have a `Severity` field instead of a getter and setter in `go.opentelemetry.io/otel/log`. (#6009)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -264,9 +264,9 @@ allocations and make it possible to handle new arguments, `Enabled` accepts
|
||||
a `EnabledParameters` struct, defined in [logger.go](logger.go), as the second
|
||||
method argument.
|
||||
|
||||
The `EnabledParameters` getters are returning values using the `(value, ok)`
|
||||
idiom in order to indicate if the values were actually set by the caller or if
|
||||
there are unspecified.
|
||||
The `EnabledParameters` uses fields, instead of getters and setters, to allow
|
||||
simpler usage which allows configuring the `EnabledParameters` in the same line
|
||||
where `Enabled` is called.
|
||||
|
||||
### noop package
|
||||
|
||||
|
@ -138,18 +138,5 @@ func WithSchemaURL(schemaURL string) LoggerOption {
|
||||
|
||||
// EnabledParameters represents payload for [Logger]'s Enabled method.
|
||||
type EnabledParameters struct {
|
||||
severity Severity
|
||||
severitySet bool
|
||||
}
|
||||
|
||||
// Severity returns the [Severity] level value, or [SeverityUndefined] if no value was set.
|
||||
// The ok result indicates whether the value was set.
|
||||
func (r *EnabledParameters) Severity() (value Severity, ok bool) {
|
||||
return r.severity, r.severitySet
|
||||
}
|
||||
|
||||
// SetSeverity sets the [Severity] level.
|
||||
func (r *EnabledParameters) SetSeverity(level Severity) {
|
||||
r.severity = level
|
||||
r.severitySet = true
|
||||
Severity Severity
|
||||
}
|
||||
|
@ -71,18 +71,13 @@ func TestLoggerEnabled(t *testing.T) {
|
||||
name string
|
||||
options []Option
|
||||
ctx context.Context
|
||||
buildEnabledParameters func() log.EnabledParameters
|
||||
|
||||
isEnabled bool
|
||||
enabledParams log.EnabledParameters
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "the default option enables every log entry",
|
||||
ctx: context.Background(),
|
||||
buildEnabledParameters: func() log.EnabledParameters {
|
||||
return log.EnabledParameters{}
|
||||
},
|
||||
|
||||
isEnabled: true,
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "with everything disabled",
|
||||
@ -92,16 +87,12 @@ func TestLoggerEnabled(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
ctx: context.Background(),
|
||||
buildEnabledParameters: func() log.EnabledParameters {
|
||||
return log.EnabledParameters{}
|
||||
},
|
||||
|
||||
isEnabled: false,
|
||||
want: false,
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := NewRecorder(tt.options...).Logger("test").Enabled(tt.ctx, tt.buildEnabledParameters())
|
||||
assert.Equal(t, tt.isEnabled, e)
|
||||
e := NewRecorder(tt.options...).Logger("test").Enabled(tt.ctx, tt.enabledParams)
|
||||
assert.Equal(t, tt.want, e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -280,10 +280,9 @@ func BenchmarkLoggerEnabled(b *testing.B) {
|
||||
WithProcessor(newFltrProcessor("0", false)),
|
||||
WithProcessor(newFltrProcessor("1", true)),
|
||||
)
|
||||
logger := provider.Logger("BenchmarkLoggerEnabled")
|
||||
ctx, param := context.Background(), log.EnabledParameters{}
|
||||
param.SetSeverity(log.SeverityDebug)
|
||||
|
||||
logger := provider.Logger(b.Name())
|
||||
ctx := context.Background()
|
||||
param := log.EnabledParameters{Severity: log.SeverityDebug}
|
||||
var enabled bool
|
||||
|
||||
b.ReportAllocs()
|
||||
|
Loading…
Reference in New Issue
Block a user