From 42c1708ed52125e6e7357f5b279b8bc28b744926 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 14 Mar 2024 13:22:12 -0700 Subject: [PATCH] Add SeverityUndefined to `otel/log` (#5072) * Add SeverityUndefined * Add changelog entry --------- Co-authored-by: Sam Xie --- CHANGELOG.md | 2 ++ log/severity.go | 3 +++ log/severity_string.go | 8 ++++---- log/severity_test.go | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 689ef03e18c..06135e0d7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906) - Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906) +- Add `SeverityUndefined` `const` to `go.opentelemetry.io/otel/log`. + This value represents an unset severity level. (#5072) ### Changed diff --git a/log/severity.go b/log/severity.go index 5ef8826a07c..0240fd5acbd 100644 --- a/log/severity.go +++ b/log/severity.go @@ -13,6 +13,9 @@ type Severity int // Severity values defined by OpenTelemetry. const ( + // SeverityUndefined represents an unset Severity. + SeverityUndefined Severity = 0 // UNDEFINED + // A fine-grained debugging log record. Typically disabled in default // configurations. SeverityTrace1 Severity = 1 // TRACE diff --git a/log/severity_string.go b/log/severity_string.go index d742ae5fe88..4c20fa5e8aa 100644 --- a/log/severity_string.go +++ b/log/severity_string.go @@ -8,6 +8,7 @@ func _() { // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. var x [1]struct{} + _ = x[SeverityUndefined-0] _ = x[SeverityTrace1-1] _ = x[SeverityTrace2-2] _ = x[SeverityTrace3-3] @@ -34,14 +35,13 @@ func _() { _ = x[SeverityFatal4-24] } -const _Severity_name = "TRACETRACE2TRACE3TRACE4DEBUGDEBUG2DEBUG3DEBUG4INFOINFO2INFO3INFO4WARNWARN2WARN3WARN4ERRORERROR2ERROR3ERROR4FATALFATAL2FATAL3FATAL4" +const _Severity_name = "UNDEFINEDTRACETRACE2TRACE3TRACE4DEBUGDEBUG2DEBUG3DEBUG4INFOINFO2INFO3INFO4WARNWARN2WARN3WARN4ERRORERROR2ERROR3ERROR4FATALFATAL2FATAL3FATAL4" -var _Severity_index = [...]uint8{0, 5, 11, 17, 23, 28, 34, 40, 46, 50, 55, 60, 65, 69, 74, 79, 84, 89, 95, 101, 107, 112, 118, 124, 130} +var _Severity_index = [...]uint8{0, 9, 14, 20, 26, 32, 37, 43, 49, 55, 59, 64, 69, 74, 78, 83, 88, 93, 98, 104, 110, 116, 121, 127, 133, 139} func (i Severity) String() string { - i -= 1 if i < 0 || i >= Severity(len(_Severity_index)-1) { - return "Severity(" + strconv.FormatInt(int64(i+1), 10) + ")" + return "Severity(" + strconv.FormatInt(int64(i), 10) + ")" } return _Severity_name[_Severity_index[i]:_Severity_index[i+1]] } diff --git a/log/severity_test.go b/log/severity_test.go index cd153d20d02..66cd8869d76 100644 --- a/log/severity_test.go +++ b/log/severity_test.go @@ -19,6 +19,12 @@ func TestSeverity(t *testing.T) { value int str string }{ + { + name: "SeverityUndefined", + severity: log.SeverityUndefined, + value: 0, + str: "UNDEFINED", + }, { name: "SeverityTrace", severity: log.SeverityTrace,