All checks were successful
DCO action / DCO (pull_request) Successful in 36s
Vulncheck / Vulncheck (pull_request) Successful in 1m9s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m28s
Build / Build Components (pull_request) Successful in 1m36s
Tests and linters / Run gofumpt (pull_request) Successful in 3m11s
Tests and linters / Tests with -race (pull_request) Successful in 3m41s
Tests and linters / Staticcheck (pull_request) Successful in 3m51s
Tests and linters / gopls check (pull_request) Successful in 3m55s
Tests and linters / Tests (pull_request) Successful in 4m3s
Tests and linters / Lint (pull_request) Successful in 4m47s
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
98 lines
2.3 KiB
Go
98 lines
2.3 KiB
Go
package logger
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkLoggerMain(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("debug"))
|
|
require.NoError(b, prm.SetAllowedTags([]string{"main:debug"}))
|
|
logger, err := NewLogger(prm)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for range b.N {
|
|
logger.Debug(ctx, "test debug")
|
|
logger.Info(ctx, "test info")
|
|
logger.Warn(ctx, "test warn")
|
|
logger.Error(ctx, "test error")
|
|
}
|
|
}
|
|
|
|
func BenchmarkLoggerLevelLessTagAllowed(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("info"))
|
|
require.NoError(b, prm.SetAllowedTags([]string{"main:debug"}))
|
|
logger, err := NewLogger(prm)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for range b.N {
|
|
logger.Debug(ctx, "test debug")
|
|
logger.Info(ctx, "test info")
|
|
logger.Warn(ctx, "test warn")
|
|
logger.Error(ctx, "test error")
|
|
}
|
|
}
|
|
|
|
func BenchmarkLoggerLevelGreaterTagAllowed(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("debug"))
|
|
require.NoError(b, prm.SetAllowedTags([]string{"main:info"}))
|
|
logger, err := NewLogger(prm)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for range b.N {
|
|
logger.Debug(ctx, "test debug")
|
|
logger.Info(ctx, "test info")
|
|
logger.Warn(ctx, "test warn")
|
|
logger.Error(ctx, "test error")
|
|
}
|
|
}
|
|
|
|
func BenchmarkLoggerLevelLessTagDisabled(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("info"))
|
|
require.NoError(b, prm.SetAllowedTags([]string{"morph:debug"}))
|
|
logger, err := NewLogger(prm)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for range b.N {
|
|
logger.Debug(ctx, "test debug")
|
|
logger.Info(ctx, "test info")
|
|
logger.Warn(ctx, "test warn")
|
|
logger.Error(ctx, "test error")
|
|
}
|
|
}
|
|
|
|
func BenchmarkLoggerLevelGreaterTagDisabled(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("debug"))
|
|
require.NoError(b, prm.SetAllowedTags([]string{"morph:info"}))
|
|
logger, err := NewLogger(prm)
|
|
require.NoError(b, err)
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
for range b.N {
|
|
logger.Debug(ctx, "test debug")
|
|
logger.Info(ctx, "test info")
|
|
logger.Warn(ctx, "test warn")
|
|
logger.Error(ctx, "test error")
|
|
}
|
|
}
|