Log cleanup pass (#2285)

* Log cleanup pass

Demoted a bunch of logs to DEBUG, consolidated logs.

* use context logger and fix context var usage

* moved common error types, fixed tests
This commit is contained in:
David Zhao
2023-12-02 15:07:31 -08:00
committed by GitHub
parent beecfe3710
commit 3fe124c87f
24 changed files with 1171 additions and 149 deletions
+20 -4
View File
@@ -16,17 +16,33 @@
package utils
import "context"
import (
"context"
var attemptKey = struct{}{}
"github.com/livekit/protocol/logger"
)
type attemptKey struct{}
type loggerKey = struct{}
func ContextWithAttempt(ctx context.Context, attempt int) context.Context {
return context.WithValue(ctx, attemptKey, attempt)
return context.WithValue(ctx, attemptKey{}, attempt)
}
func GetAttempt(ctx context.Context) int {
if attempt, ok := ctx.Value(attemptKey).(int); ok {
if attempt, ok := ctx.Value(attemptKey{}).(int); ok {
return attempt
}
return 0
}
func ContextWithLogger(ctx context.Context, logger logger.Logger) context.Context {
return context.WithValue(ctx, loggerKey{}, logger)
}
func GetLogger(ctx context.Context) logger.Logger {
if l, ok := ctx.Value(loggerKey{}).(logger.Logger); ok {
return l
}
return logger.GetLogger()
}