move logging to protocol (#109)
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/stun"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
+15
-49
@@ -1,8 +1,8 @@
|
||||
package logger
|
||||
package serverlogger
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/go-logr/zapr"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/ion-sfu/pkg/buffer"
|
||||
"github.com/pion/ion-sfu/pkg/sfu"
|
||||
"github.com/pion/logging"
|
||||
@@ -11,28 +11,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// pion/ion-sfu
|
||||
defaultLogger = logr.Discard()
|
||||
// pion/webrtc, pion/turn
|
||||
defaultFactory logging.LoggerFactory
|
||||
)
|
||||
|
||||
// Note: already with extra depth 1
|
||||
func GetLogger() logr.Logger {
|
||||
if defaultLogger == logr.Discard() {
|
||||
InitDevelopment("")
|
||||
}
|
||||
return defaultLogger
|
||||
}
|
||||
|
||||
// Note: only pass in logr.Logger with default depth
|
||||
func SetLogger(l logr.Logger) {
|
||||
sfu.Logger = l.WithName("sfu")
|
||||
buffer.Logger = sfu.Logger
|
||||
|
||||
defaultLogger = l.WithCallDepth(1).WithName("livekit")
|
||||
}
|
||||
|
||||
func LoggerFactory() logging.LoggerFactory {
|
||||
if defaultFactory == nil {
|
||||
defaultFactory = logging.NewDefaultLoggerFactory()
|
||||
@@ -44,6 +26,14 @@ func SetLoggerFactory(lf logging.LoggerFactory) {
|
||||
defaultFactory = lf
|
||||
}
|
||||
|
||||
func InitProduction(logLevel string) {
|
||||
initLogger(zap.NewProductionConfig(), logLevel)
|
||||
}
|
||||
|
||||
func InitDevelopment(logLevel string) {
|
||||
initLogger(zap.NewDevelopmentConfig(), logLevel)
|
||||
}
|
||||
|
||||
// valid levels: debug, info, warn, error, fatal, panic
|
||||
func initLogger(config zap.Config, level string) {
|
||||
if level != "" {
|
||||
@@ -53,33 +43,9 @@ func initLogger(config zap.Config, level string) {
|
||||
}
|
||||
}
|
||||
|
||||
logger, _ := config.Build()
|
||||
SetLogger(zapr.NewLogger(logger))
|
||||
}
|
||||
|
||||
func InitProduction(logLevel string) {
|
||||
initLogger(zap.NewProductionConfig(), logLevel)
|
||||
}
|
||||
|
||||
func InitDevelopment(logLevel string) {
|
||||
initLogger(zap.NewDevelopmentConfig(), logLevel)
|
||||
}
|
||||
|
||||
func Debugw(msg string, keysAndValues ...interface{}) {
|
||||
defaultLogger.V(1).Info(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Infow(msg string, keysAndValues ...interface{}) {
|
||||
defaultLogger.Info(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Warnw(msg string, err error, keysAndValues ...interface{}) {
|
||||
if err != nil {
|
||||
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
|
||||
}
|
||||
defaultLogger.Info(msg, keysAndValues...)
|
||||
}
|
||||
|
||||
func Errorw(msg string, err error, keysAndValues ...interface{}) {
|
||||
defaultLogger.Error(err, msg, keysAndValues...)
|
||||
l, _ := config.Build()
|
||||
zapLogger := zapr.NewLogger(l)
|
||||
sfu.Logger = zapLogger.WithName("sfu")
|
||||
buffer.Logger = sfu.Logger
|
||||
logger.SetLogger(zapLogger, "livekit")
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
)
|
||||
|
||||
// a router of messages on the same node, basic implementation for local testing
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/utils/stats"
|
||||
)
|
||||
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
serverlogger "github.com/livekit/livekit-server/pkg/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -41,7 +41,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
|
||||
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
|
||||
}
|
||||
s := webrtc.SettingEngine{
|
||||
LoggerFactory: logger.LoggerFactory(),
|
||||
LoggerFactory: serverlogger.LoggerFactory(),
|
||||
}
|
||||
|
||||
if externalIP != "" {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/ion-sfu/pkg/buffer"
|
||||
@@ -16,7 +17,6 @@ import (
|
||||
"github.com/pion/webrtc/v3/pkg/rtcerr"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/utils/stats"
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/ion-sfu/pkg/sfu"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/utils/stats"
|
||||
|
||||
+1
-1
@@ -7,13 +7,13 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/ion-sfu/pkg/buffer"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/utils/stats"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
serverlogger "github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger.InitDevelopment("")
|
||||
serverlogger.InitDevelopment("")
|
||||
}
|
||||
|
||||
func TestJoinedState(t *testing.T) {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
func checkUDPReadBuffer() {
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bep/debounce"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/pion/interceptor"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/utils/stats"
|
||||
)
|
||||
|
||||
|
||||
+1
-1
@@ -6,10 +6,10 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gammazero/workerpool"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/pkg/rtc"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/turn/v2"
|
||||
@@ -18,7 +19,6 @@ import (
|
||||
"github.com/urfave/negroni"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
"github.com/livekit/livekit-server/version"
|
||||
)
|
||||
|
||||
+3
-2
@@ -6,11 +6,12 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/pion/turn/v2"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
serverlogger "github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
)
|
||||
|
||||
@@ -34,7 +35,7 @@ func NewTurnServer(conf *config.Config, roomStore RoomStore, node routing.LocalN
|
||||
serverConfig := turn.ServerConfig{
|
||||
Realm: livekitRealm,
|
||||
AuthHandler: newTurnAuthHandler(roomStore),
|
||||
LoggerFactory: logger.LoggerFactory(),
|
||||
LoggerFactory: serverlogger.LoggerFactory(),
|
||||
}
|
||||
relayAddrGen := &turn.RelayAddressGeneratorPortRange{
|
||||
RelayAddress: net.ParseIP(node.Ip),
|
||||
|
||||
@@ -10,13 +10,13 @@ import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/google/wire"
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user