[#1673] logger: Add sampling for journald logger
All checks were successful
DCO action / DCO (pull_request) Successful in 30s
Vulncheck / Vulncheck (pull_request) Successful in 1m5s
Build / Build Components (pull_request) Successful in 1m26s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m29s
Tests and linters / Run gofumpt (pull_request) Successful in 2m23s
Tests and linters / Lint (pull_request) Successful in 2m46s
Tests and linters / Staticcheck (pull_request) Successful in 2m47s
Tests and linters / Tests (pull_request) Successful in 3m1s
Tests and linters / Tests with -race (pull_request) Successful in 3m40s
Tests and linters / gopls check (pull_request) Successful in 3m47s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-03-13 10:37:29 +03:00
parent a13e12e3de
commit e59b426d39
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0

View file

@ -2,6 +2,7 @@ package logger
import (
"fmt"
"time"
"git.frostfs.info/TrueCloudLab/zapjournald"
"github.com/ssgreg/journald"
@ -166,7 +167,18 @@ func newJournaldLogger(prm *Prm) (*Logger, error) {
zapjournald.SyslogPid(),
})
lZap := zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), zap.AddCallerSkip(1))
var samplerOpts []zapcore.SamplerOption
if c.Sampling.Hook != nil {
samplerOpts = append(samplerOpts, zapcore.SamplerHook(c.Sampling.Hook))
}
samplingCore := zapcore.NewSamplerWithOptions(
coreWithContext,
time.Second,
c.Sampling.Initial,
c.Sampling.Thereafter,
samplerOpts...,
)
lZap := zap.New(samplingCore, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), zap.AddCallerSkip(1))
l := &Logger{z: lZap, lvl: lvl}
prm._log = l