forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add LogMessage and move LogStabilityLevel (open-telemetry#5633)
* add LogMessage and move LogStabilityLevel This change will make the func available for extensions as well. * add docstring * fix typo * fix impi * apply review feedback
- Loading branch information
Alex Boten
authored
Jul 13, 2022
1 parent
6417a3a
commit 6266e5b
Showing
5 changed files
with
109 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package components // import "go.opentelemetry.io/collector/service/internal/components" | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// LogStabilityLevel logs the stability level of a component. The log level is set to info for | ||
// undefined, unmaintained, deprecated and in development. The log level is set to debug | ||
// for alpha, beta and stable. | ||
func LogStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) { | ||
if sl >= component.StabilityLevelAlpha { | ||
logger.Debug(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) | ||
} else { | ||
logger.Info(sl.LogMessage(), zap.String(ZapStabilityKey, sl.String())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package components // import "go.opentelemetry.io/collector/service/internal/components" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
"go.uber.org/zap/zaptest/observer" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
func TestLogStabilityLevel(t *testing.T) { | ||
tests := []struct { | ||
level zapcore.Level | ||
expectedLogs int | ||
}{ | ||
{ | ||
level: zapcore.DebugLevel, | ||
expectedLogs: 7, | ||
}, | ||
{ | ||
level: zapcore.InfoLevel, | ||
expectedLogs: 4, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
observed, logs := observer.New(tt.level) | ||
logger := zap.New(observed) | ||
// ensure log levels are set correctly for each stability level | ||
LogStabilityLevel(logger, component.StabilityLevelUndefined) | ||
LogStabilityLevel(logger, component.StabilityLevelUnmaintained) | ||
LogStabilityLevel(logger, component.StabilityLevelDeprecated) | ||
LogStabilityLevel(logger, component.StabilityLevelInDevelopment) | ||
LogStabilityLevel(logger, component.StabilityLevelAlpha) | ||
LogStabilityLevel(logger, component.StabilityLevelBeta) | ||
LogStabilityLevel(logger, component.StabilityLevelStable) | ||
require.Equal(t, tt.expectedLogs, logs.Len()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters