[#1673] logger: Add sampling for journald logger
All checks were successful
DCO action / DCO (pull_request) Successful in 29s
Vulncheck / Vulncheck (pull_request) Successful in 58s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m25s
Build / Build Components (pull_request) Successful in 1m27s
Tests and linters / Run gofumpt (pull_request) Successful in 2m41s
Tests and linters / Tests (pull_request) Successful in 3m13s
Tests and linters / gopls check (pull_request) Successful in 3m15s
Tests and linters / Lint (pull_request) Successful in 3m25s
Tests and linters / Staticcheck (pull_request) Successful in 3m21s
Tests and linters / Tests with -race (pull_request) Successful in 4m42s
Vulncheck / Vulncheck (push) Successful in 1m8s
Pre-commit hooks / Pre-commit (push) Successful in 1m19s
Build / Build Components (push) Successful in 2m7s
Tests and linters / Tests with -race (push) Successful in 2m42s
Tests and linters / Staticcheck (push) Successful in 3m1s
Tests and linters / Tests (push) Successful in 3m19s
Tests and linters / Run gofumpt (push) Successful in 3m15s
Tests and linters / Lint (push) Successful in 3m52s
Tests and linters / gopls check (push) Successful in 4m6s
OCI image / Build container images (push) Successful in 4m42s

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 ff4e9b6ae1
commit 7893d763d1
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