Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow setting min log level for logger #705

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion infra/link.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_agent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_analytics.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_egress.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_ingress.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_internal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_models.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_room.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_rtc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_sip.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion livekit/livekit_webhook.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type ZapLogger interface {
Logger
ToZap() *zap.SugaredLogger
ComponentLeveler() ZapComponentLeveler
WithMinLevel(lvl zapcore.LevelEnabler) Logger
}

type zapLogger[T zaputil.Encoder[T]] struct {
Expand All @@ -198,6 +199,7 @@ type zapLogger[T zaputil.Encoder[T]] struct {
component string
deferred []*zaputil.Deferrer
sampler *zaputil.Sampler
minLevel zapcore.LevelEnabler
}

func FromZapLogger(log *zap.Logger, conf *Config, opts ...ZapLoggerOption) (ZapLogger, error) {
Expand Down Expand Up @@ -253,9 +255,15 @@ func newZapLogger[T zaputil.Encoder[T]](zap *zap.SugaredLogger, zc *zapConfig, e
}

func (l *zapLogger[T]) ToZap() *zap.SugaredLogger {
console, _ := l.writeEnablers.LoadOrCompute(l.component, func() *zaputil.WriteEnabler {
return zaputil.NewWriteEnabler(os.Stderr, l.sc.ComponentLevel(l.component))
})
var console *zaputil.WriteEnabler
if l.minLevel == nil {
console, _ = l.writeEnablers.LoadOrCompute(l.component, func() *zaputil.WriteEnabler {
return zaputil.NewWriteEnabler(os.Stderr, l.sc.ComponentLevel(l.component))
})
} else {
enab := zaputil.OrLevelEnabler{l.minLevel, l.sc.ComponentLevel(l.component)}
console = zaputil.NewWriteEnabler(os.Stderr, enab)
}

c := l.enc.Core(console, l.tap)
for i := range l.deferred {
Expand Down Expand Up @@ -291,6 +299,13 @@ func (l *zapLogger[T]) Debugw(msg string, keysAndValues ...interface{}) {
l.zap.Debugw(msg, keysAndValues...)
}

func (l *zapLogger[T]) WithMinLevel(lvl zapcore.LevelEnabler) Logger {
dup := *l
dup.minLevel = lvl
dup.zap = dup.ToZap()
return &dup
}

func (l *zapLogger[T]) Infow(msg string, keysAndValues ...interface{}) {
l.zap.Infow(msg, keysAndValues...)
}
Expand Down
2 changes: 1 addition & 1 deletion logger/pionlogger/logadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// implements webrtc.LeveledLogger
type logAdapter struct {
logger logger.Logger
ignoredPrefixes prefixSet
ignoredPrefixes *prefixSet
}

func (l *logAdapter) Trace(msg string) {
Expand Down
10 changes: 7 additions & 3 deletions logger/pionlogger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

var (
pionIgnoredPrefixes = map[string]prefixSet{
pionIgnoredPrefixes = map[string]*prefixSet{
"ice": {
"pingAllCandidates called with no candidate pairs",
"failed to send packet: io: read/write on closed pipe",
Expand Down Expand Up @@ -52,8 +52,12 @@ var (

type prefixSet []string

func (s prefixSet) Match(msg string) bool {
for _, prefix := range s {
func (s *prefixSet) Match(msg string) bool {
if s == nil {
return false
}

for _, prefix := range *s {
if strings.HasPrefix(msg, prefix) {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion logger/pionlogger/zaplogadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type zapLogAdapter struct {
logger logger.Logger
level zapcore.LevelEnabler
scope string
ignoredPrefixes prefixSet
ignoredPrefixes *prefixSet
}

func (l *zapLogAdapter) init() {
Expand Down
2 changes: 1 addition & 1 deletion rpc/agent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/egress.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/ingress.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/io.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/keepalive.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/participant.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/room.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/signal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/sip.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/hedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type HedgeParams[T any] struct {
Func func(context.Context) (T, error)
}

// race retries if the function takes to long to return
// race retries if the function takes too long to return
// |---------------- attempt 1 ----------------|
// | delay |--------- attempt 2 ---------|
func HedgeCall[T any](ctx context.Context, params HedgeParams[T]) (v T, err error) {
Expand Down
Loading